Simpatie.ro - matrimoniale
Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Nou pe simpatie:
Isabela_9my din Constanta
Femeie
24 ani
Constanta
cauta Barbat
32 - 48 ani
Mrrrr's Forum (VIEW ONLY)ReguliInregistrareLoginPozeNu sunteti logat. Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides /

[WORD] Add Insert Page X of Y Toggle to QAT [VBA]

Pagini: 1 Moderat de TRaP, TonyTzu
#1
TRaP
Moderator
Postari: 960
First, let's insert page number the old fashioned way (Insert - Page Number - Current Position - Page X of Y).

Now edit / customize the result to your desire (mine is Pagina 1 / 1), then select it, then go again to Insert - Page Number - Current Position and at the bottom of the list (not in the list itself) you will have to click on Save Selection to Page Number Gallery...

A new box will appear where you need to complete the following:
Name: The name of your Building Block, eg Pagina X / Y --- you will need this name in your VBA code below.
Gallery: Page Numbers
Category: Page X of Y (in this case, you can select whatever fits your custom page number best)
Description: optional
Save in: Normal (I'd recommend it to be Normal because that's where all your macros are stored too)
Options: Insert content only

Click OK

Now open VBA (ALT+F11), create a new module and paste the following:


Sub PageXofY()

Application.Templates _
("C:\Users\CURRENT USER NAME\AppData\Roaming\Microsoft\Templates\Normal.dotm") _
.BuildingBlockEntries("Pagina X / Y").Insert Where:=Selection.Range, RichText:=True

End Sub


Note that you have to replace CURRENT USER NAME with your user name, and Pagina X / Y with the name you defined before.


 
   
#2
TRaP
Moderator
Postari: 960
Updated

 
   
#3
Mrrrr
AdMiN
Postari: 2388
I used an even more advanced way of inserting a page number by creating a user form to do it in more than one way, by choice:




Private Sub CommandButton1_Click()

' INSERT PAGE NUMBERS IN THE FORM: Pag. X / Y
With Word.Application.ActiveDocument
        Selection.TypeText Text:="Pag. "
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "PAGE ", PreserveFormatting:=True
        Selection.TypeText Text:=" / "
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "NUMPAGES ", PreserveFormatting:=True
End With
End Sub

Private Sub CommandButton2_Click()

' INSERT PAGE NUMBERS IN THE FORM: Pag. X din Y
With Word.Application.ActiveDocument
        Selection.TypeText Text:="Pag. "
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "PAGE ", PreserveFormatting:=True
        Selection.TypeText Text:=" din "
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "NUMPAGES ", PreserveFormatting:=True
End With
End Sub

Private Sub CommandButton3_Click()

' INSERT PAGE NUMBERS IN THE FORM: Pagina X / Y
With Word.Application.ActiveDocument
        Selection.TypeText Text:="Pagina "
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "PAGE ", PreserveFormatting:=True
        Selection.TypeText Text:=" / "
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "NUMPAGES ", PreserveFormatting:=True
End With
End Sub

Private Sub CommandButton4_Click()

' INSERT PAGE NUMBERS IN THE FORM: Pagina X din Y
With Word.Application.ActiveDocument
        Selection.TypeText Text:="Pagina "
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "PAGE ", PreserveFormatting:=True
        Selection.TypeText Text:=" din "
        Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
            "NUMPAGES ", PreserveFormatting:=True
End With
End Sub

Private Sub CommandButton5_Click()
    Unload FormPageXofY
End Sub


_______________________________________


 
   
Pagini: 1  
Mergi la