Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Dec 2000
    Location
    Montreal, Quebec, Canada
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Inserting a page number in a footer (Office 2000)

    Hello,
    I am trying to create a macro that will insert the word "page" and a page number in the footer. I got the word "page" in correctly but I can't seem to get the page number in it. The best I could do was to have the page number in the document or to have it inserted at the bottom right of the page. Please help.

    With .Footers(wdHeaderFooterPrimary)
    .Range.InsertAfter ("Page ")
    ??????
    End With

    I might also be diring the wrong lane here.
    Tks for your help.

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Inserting a page number in a footer (Office 2000)

    ???? = .Range.Fields.Add Range:=.Range, Type:=wdFieldPage

    StuartR

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Inserting a page number in a footer (WD2000)

    Sometimes there is no way to insert content into a Range without destroying the existing content. In these cases, an effective approach is to declare a range variable, set it equal to the target range, and then collapse it to its endpoint and insert the content there (assuming the new content should come at the end). I believe there are examples of this in the Lounge, but if they are difficult to find, it would not be hard to whip up a new one.

  4. #4
    2 Star Lounger
    Join Date
    Dec 2000
    Location
    Montreal, Quebec, Canada
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Inserting a page number in a footer (Office 2000)

    Tks Stuart it works but I lost the word "Page" before the page number.
    Help!

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Inserting a page number in a footer (Office 2000)

    Looks like Jefferson read your mind.

    Simplest solution. Change the order of the two lines and change InsertAfter to be InsertBefore

    Harder Solution...

    <code>Dim rngTemp as Range
    With .Footers(wdHeaderFooterPrimary)
    .Range.InsertAfter ("Page ")
    set rngTemp = .Range.Duplicate
    rngTemp.Collapse Direction:=wdCollapseEnd
    rngTemp.Fields.Add Range:=rngTemp, Type:=wdFieldPage
    set rngTemp = Nothing
    End With
    </code>

    This code not tested, just typed in to the editor here, but you can see the idea.

    StuartR

  6. #6
    2 Star Lounger
    Join Date
    Dec 2000
    Location
    Montreal, Quebec, Canada
    Posts
    115
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Inserting a page number in a footer (Office 2000)

    Tks to both of you.
    Insert before is the simplest solution and it works just fine.
    Yeah!

Posting Permissions

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