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.
Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login

POZE MRRRR'S FORUM (VIEW ONLY)

Nu sunteti logat.
Nou pe simpatie:
the_clasik_ely 24 ani
Femeie
24 ani
Hunedoara
cauta Barbat
24 - 80 ani
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides / [WORD] Add EditBox on Ribbon to Go To Page Number [VBA, XML] Moderat de TRaP, TonyTzu
Autor
Mesaj Pagini: 1
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
If you don't know how to create and edit a custom ribbon for Word, I'll make it simple:

1. Open Word and save file as CustomRibbon.dotm

2. Open Visual Basic (ALT+F11) and create a new module, where you paste the following, then save and close file:

Option Explicit
Public myRibbon As IRibbonUI
Public PagNum As String

Public Sub rbnOnLoad(control As IRibbonUI)
    Set myRibbon = control
End Sub

Public Sub GetText(control As IRibbonControl, ByRef Text)
'    Text = PagNum 'NOTE: you can enable this if you want the last page number you type to remain in the EditBox - note also that if you scroll to another page, the number in the EditBox won't change
    PagNum = Text
End Sub

Public Sub EditBoxOnChange(control As IRibbonControl, Text As String)

With ActiveDocument

Dim AllPages As Integer
    AllPages = ActiveDocument.Range.Information(wdNumberOfPagesInDocument)
   
    PagNum = Text
    myRibbon.InvalidateControl ("PagNumText")
       
If PagNum > AllPages Then
    MsgBox "This document doesn't have " & PagNum & " pages," & vbCrLf & _
            "it has " & AllPages & " pages", vbOKOnly
Else
    Selection.GoTo What:=wdGoToPage, Name:=PagNum
End If

End With
End Sub


3. Download CustomUI Editor:

4. After you install, open it, then open the dotm file you saved above.

5. Add the following code to it, then save and close:


<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="rbnOnLoad">

<ribbon><tabs><tab id="customTab" label="BEST" insertBeforeMso="TabHome">

<editBox  id="PagNumText"
              label="Page"
          getText="GetText"
              onChange="EditBoxOnChange"
              sizeString="XXX" />

</group></tab></tabs></ribbon></customUI>


6. Open the CustomRibbon.dotm file again by right clicking on it and selecting Open (otherwise it will open a new file).

7. On the first line of your document type: =rand(20,20) and press enter - this will generate about 7 pages of text and it will jump to last page.

8. Go to the newly created ribbon called BEST, click inside the EditBox and type 1 then press enter - Word should jump on page 1. Type 5 and it should go to page 5. Type 8 and it will give you an error: "This document doesn't have 8 pages"

Note:
If you want this custom ribbon to load for every word document, then with all Word windows closed, copy the CustomRibbon.dotm file to: %AppData%\Microsoft\word\STARTUP


_______________________________________


pus acum 5 ani
   
Pagini: 1  

Mergi la