Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Mar 2002
    Location
    baltimore, md, USA
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm inserting a page number like this which is directly out of pagenumber help.

    Dim MyDoc As Document
    Set MyDoc = Application.ActiveDocument
    With MyDoc.Sections(1).Footers(wdHeaderFooterPrimary)
    .PageNumbers.Add PageNumberAlignment:=wdAlignPageNumberCenter
    End With

    The problem is that the page number is in a frame and the frame has first line indent = .5 which makes the page number look off center.

    How do I change the frame's alignment to be first line indent = 0?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Quote Originally Posted by dplaut View Post
    The problem is that the page number is in a frame and the frame has first line indent = .5 which makes the page number look off center.
    In Word 2003, I don't see a first line indent setting for the frame. Does it help if you make the position of the frame relative to the page rather than the margins?

    Code:
    Dim MyDoc As Document
    Set MyDoc = Application.ActiveDocument
    With MyDoc.Sections(1).Footers(wdHeaderFooterPrimary)
        .PageNumbers.Add PageNumberAlignment:=wdAlignPageNumberCenter
        ' Change centering from between margins to between edges of the page
        .Range.Frames(1).RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
    End With
    (Note: this snippet assumes that the page number frame is the first frame in the footer.)

  3. #3
    New Lounger
    Join Date
    Mar 2002
    Location
    baltimore, md, USA
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jscher2000 View Post
    Does it help if you make the position of the frame relative to the page rather than the margins?
    No, that did not make any difference.

    I'm using Word 2007.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Can you post a sample document with this problem? It doesn't actually need anything in the body, unless that has some effect on the position of the page number.

  5. #5
    New Lounger
    Join Date
    Mar 2002
    Location
    baltimore, md, USA
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It seems to happen when the Normal style is set to First line indent = .5"

    I guess that explains it but why some MS programmer thought anyone would want to indent a centered page number is beyond me.

  6. #6
    WS Lounge VIP
    Join Date
    Mar 2006
    Location
    Maryland, USA
    Posts
    690
    Thanks
    17
    Thanked 66 Times in 56 Posts
    In W2007, the Footer paragraph style is based on (takes format settings from) normal. If your normal has a .5 indent, so will your footer. If you don't want that, modify the style.

    HTH,
    Pam
    Pam Caswell

  7. #7
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts
    The source of the problem is that the code:

    .PageNumbers.Add

    - is doing something very bad, which is to insert the page number in a frame. Putting the page number in a frame is really unnecessary, and I think frames themselves have been sort of deprecated since at least Word 2000. So it's a shame that that code still inserts with a frame.

    To insert the page number without a frame, you can insert it as a field - try the following code instead:

    Code:
       Dim MyDoc As Document
       Set MyDoc = Application.ActiveDocument
       With MyDoc.Sections(1).Footers(wdHeaderFooterPrimary)
          .Range.Fields.Add Range:=.Range, Type:=wdFieldPage
          .Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
       End With
       Set MyDoc = Nothing
    Gary

Posting Permissions

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