Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Apr 2002
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word VBA Footer problem (Word XP)

    <hr>
    '----------------Footer Section -------------------------------------------
    '--------------remove protection-----------------------
    If ActiveDocument.ProtectionType <> wdNoProtection Then
    ActiveDocument.Unprotect
    End If

    If foot_add = True Then

    '--------------------------------------Add Footer text-------------
    If foot_page = True Then '-----------show text on first page
    ActiveDocument.PageSetup.DifferentFirstPageHeaderF ooter = False
    ActiveDocument.Sections(1).Footers(wdHeaderFooterP rimary).Range.Text = txtourref.Text
    Else '------------ dont show footer text on first page
    ActiveDocument.PageSetup.DifferentFirstPageHeaderF ooter = True
    ActiveDocument.Sections(1).Footers(wdHeaderFooterP rimary).Range.Text = txtourref.Text
    End If

    '-------------------------------------Add Page Numbers-------------

    End If

    If foot_num = True Then
    If foot_first = True Then '-----------show number on first page
    ActiveDocument.Sections(1).Footers(1).PageNumbers. Add PageNumberAlignment:= _
    wdAlignPageNumberRight, FirstPage:=True
    Else '----------------don't show number on first page
    ActiveDocument.Sections(1).Footers(1).PageNumbers. Add PageNumberAlignment:= _
    wdAlignPageNumberRight, FirstPage:=False
    End If
    End If

    '-----------reprotect------------
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
    noreset:=True
    '----------------------------

    <hr>
    This code is called from a form which has the following two option boxes on it.

    Add Footer ?
    Add Page Numbers ?

    Selecting either of them, give the next options respectivly

    Show Footer on first page ?
    Show Page Number on First Page ?

    The Values in the above code are as follows

    Add Footer = foot_add
    Add Pagenumbers = foot_num

    Show footer on first page = foot_page
    show page on first page = foot_first

    nb. the idea behind this, is if they select footer then the text of the value txtourref.Text is entered into the footer.

    I know the names are a bit confusing, but unfortunatly not my choice.

    The problem i am having is, its all working well, except when i want to

    Show Footer,
    Show footer on first page
    Show page number
    show page number not on the first page

    anyone see where i am going wrong

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Word VBA Footer problem (Word XP)

    Which section is it that you actually want to attack. Your code deals with Section(1) and also with the complete document. If there are already page numbers there and the user choses not to add a page number then your code doesn't appear to remove the existing numbering.

    When you ask to 'Show the Footer' are you asking to display the headers and footer on screen OR in a user form OR just do what the code intended?

    I would take a step back and create four different autotext entries. These entries should contain each of the Footer variants:
    1. First page numbered
    2. First page non-numbered
    3. Primary footer numbered
    4. Primary footer non-numbered

    Then your code should replace the existing footers completely by adding the autotext entry to that location. Example code below:
    <pre> Dim aRange1F As Range, aRangeF As Range
    Set aRange1F = ActiveDocument.Sections(1).Footers(wdHeaderFooterF irstPage).Range
    Set aRangeF = ActiveDocument.Sections(1).Footers(wdHeaderFooterP rimary).Range

    ActiveDocument.AttachedTemplate.AutoTextEntries("F ooterFirst").Insert Where:=aRange1F, RichText:=True
    aRange1F.Collapse Direction:=wdCollapseEnd
    aRange1F.Delete 'removes the extra return which wasn't part of the autotext</pre>

    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Star Lounger
    Join Date
    Apr 2002
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word VBA Footer problem (Word XP)

    This code is called when the user creates a new document from one of their templates. There is a custom toolbar which they use to load these templates.

    when they choose a template, a form pops up asking them if they want to include X/Y/Z in the document and also creates a reference. at the bottom of this form is the section I am working on.

    With the option "show footer" This puts the reference generated by the form , into the footer of the document with the option whether to show this on the first page or not.

  4. #4
    Star Lounger
    Join Date
    Apr 2002
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word VBA Footer problem (Word XP)

    <hr>
    '----------------Footer Section -------------------------------------------

    '--------------remove protection-----------------------
    If ActiveDocument.ProtectionType <> wdNoProtection Then
    ActiveDocument.Unprotect
    End If

    If foot_add = True Then

    '--------------------------------------Add Footer text-------------
    If foot_page = True Then '-----------show text on first page
    ActiveDocument.PageSetup.DifferentFirstPageHeaderF ooter = True
    ActiveDocument.Sections(1).Footers(wdHeaderFooterF irstPage).Range.Text = txtourref.Text
    ActiveDocument.Sections(1).Footers(wdHeaderFooterF irstPage).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
    ActiveDocument.Sections(1).Footers(wdHeaderFooterP rimary).Range.Text = txtourref.Text
    ActiveDocument.Sections(1).Footers(wdHeaderFooterP rimary).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
    Else '------------ dont show footer text on first page
    ActiveDocument.PageSetup.DifferentFirstPageHeaderF ooter = True
    ActiveDocument.Sections(1).Footers(wdHeaderFooterP rimary).Range.Text = txtourref.Text
    ActiveDocument.Sections(1).Footers(wdHeaderFooterP rimary).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
    End If

    '-------------------------------------Add Page Numbers-------------

    End If

    If foot_num = True Then
    If foot_first = True Then '-----------show number on first page

    ActiveDocument.Sections(1).Footers(wdHeaderFooterP rimary).PageNumbers.Add PageNumberAlignment:= _
    wdAlignPageNumberRight, FirstPage:=True
    Else '----------------don't show number on first page
    ActiveDocument.Sections(1).Footers(wdHeaderFooterP rimary).PageNumbers.Add PageNumberAlignment:= _
    wdAlignPageNumberRight, FirstPage:=False
    End If
    End If

    '-----------reprotect------------
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
    noreset:=True
    '----------------------------



    <hr>

    This is where i am so far, this works exactly how i want except for the combination

    Show Footer = true
    Show page numbers = true
    show page numbers on first page = true
    show footer on first page = false

  5. #5
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Word VBA Footer problem (Word XP)

    I assume that under those conditions that you intend to turn off the DifferentFirstPage HeaderFooter so you would need to modify the following code to say False
    Else '------------ dont show footer text on first page
    ActiveDocument.PageSetup.DifferentFirstPageHeaderF ooter = True
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  6. #6
    Star Lounger
    Join Date
    Apr 2002
    Posts
    67
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word VBA Footer problem (Word XP)

    that doesnt have the desired effect.

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

    Re: Word VBA Footer problem (Word XP)

    I don't think you will ever get this code to work the way you expect.

    I have just looked at the help file for PageNumbers.Add FirstPage:=False and it seems to describe what you expect - but I don't believe it.

    You need to make one decision about whether to have a different first page or not - and then stick with it. If you want the first page footer different in any way, including display of page number, then set DifferentFirstPageHeaderFooter = True and create two footers with the correct content. If you want both footers identical then set DifferentFirstPageHeaderFooter = False.

    StuartR

Posting Permissions

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