Consulting

Results 1 to 3 of 3

Thread: Inserting page numbers

  1. #1
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    229
    Location

    Inserting page numbers

    I've been trying use the macro recorder to insert page numbers (1 of x) in the footer. The recorder is giving me weird code. It works but I'm concerned with the line ""C:\Users\kilroy\AppData\Roaming\Microsoft\Document Building Blocks\1033\16\Built-In Building Blocks.dotx"" I'm not sure that if I'm not using this macro on my computer it will work. Is there any way to simplify??

    Sub PageNumbers()
    '
    ' PageNumbers Macro
    ' PageNumbers
    '
        If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
            ActiveWindow.Panes(2).Close
        End If
        If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
            ActivePane.View.Type = wdOutlineView Then
            ActiveWindow.ActivePane.View.Type = wdPrintView
        End If
        ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
        Application.Templates( _
            "C:\Users\******xx\AppData\Roaming\Microsoft\Document Building Blocks\1033\16\Built-In Building Blocks.dotx" _
            ).BuildingBlockEntries("Bold Numbers 3").Insert Where:=Selection.Range, _
            RichText:=True
        If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
            ActiveWindow.Panes(2).Close
        End If
        If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
            ActivePane.View.Type = wdOutlineView Then
            ActiveWindow.ActivePane.View.Type = wdPrintView
        End If
        ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
        Selection.EscapeKey
    End Sub

  2. #2
    If you change the line to
        Application.Templates( _
                Environ("APPDATA") & "\Microsoft\Document Building Blocks\1033\" & Val(Application.Version) & "\Built-In Building Blocks.dotx" _
                                   ).BuildingBlockEntries("Bold Numbers 3").Insert _
                                   Where:=Selection.Range, _
                                   RichText:=True
    It will be transportable. You could however create the same effect with a simpler code
    Sub PageNumbers2()
    Dim oRng As Range
        Set oRng = ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
        Application.Templates(Environ("APPDATA") & "\Microsoft\Document Building Blocks\1033\" & _
                                   Val(Application.Version) & _
                                   "\Built-In Building Blocks.dotx").BuildingBlockEntries("Bold Numbers 3").Insert _
                                   Where:=oRng, RichText:=True
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    229
    Location
    Thanks Graham the second code works great. I'm grateful for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •