Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Christchurch, New Zealand
    Posts
    250
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Word 2007 and 2010 - Editing Footers

    I am trying to edit a macro that was written prior to 2007. It edits the footer/s in a document. As I am having problems with the macro, I decided to take a step back and try and record editing the footer.

    In Word 2007 it records:

    WordBasic.ViewFooterOnly
    Selection.TypeText Text:="my footer"
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

    In Word 2010 I get:

    Selection.TypeText Text:="my footer"
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

    Previous versions would show me entering footer:

    ActiveWindow.ActivePane.View.SeekView = wdSeekFirstPageFooter
    or
    ActiveWindow.ActivePane.View.SeekView - wdSeekPrimaryFooter

    If I run the older macro it will enter the first page footer, but can't manage the primary footer.

    I would be grateful for any ideas as to how to actually get the functionality I need.

    Thanks.

  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
    Recording in Word 2007 I got this (lightly edited for readability):

    Code:
        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 = wdSeekPrimaryFooter
        Selection.TypeText Text:="NEWTEXT"
        ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    There are methods that do not require changing the view to moving the selection, but they can be a little messy to use when there is existing text in the footer.

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts
    I think youl'll find it easier to deal with the footers as Ranges. Try the following code. As Jefferson suggested, things can get messy, particularly if you are dealing with fields, such as page numbers. If you need to add text, the code below will help you. If you want to edit what's there, perhaps Replace() will do the job.

    Sub EditFooters()
    Dim rngFirst As Range
    Dim rngPri As Range
    Dim sFirstText As String
    Dim sPriText As String
    Set rngFirst = ActiveDocument.Sections(1).Footers(wdHeaderFooterF irstPage).Range
    Set rngPri = ActiveDocument.Sections(1).Footers(wdHeaderFooterP rimary).Range

    ' Get text of footers
    sFirstText = rngFirst.Text
    sPriText = rngPri.Text

    ' Set text of footers
    rngFirst.Text = "Text for first page footer"
    rngPri.Text = "Text for primary footer"

    ' Or... add to text that is already in footers
    rngFirst.Text = sFirstText & vbCr & "Another paragraph for first page footer text."
    rngPri.Text = sPriText & vbCr & "Another paragraph for primary footer text."

    End Sub

  4. The Following User Says Thank You to richardbarrett For This Useful Post:

    KarenWright (2012-09-03)

  5. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Christchurch, New Zealand
    Posts
    250
    Thanks
    1
    Thanked 0 Times in 0 Posts
    This has been helpful, thank you. (Now I need to change my settings so I get an email when I get a reply )

  6. #5
    3 Star Lounger
    Join Date
    Apr 2012
    Posts
    240
    Thanks
    3
    Thanked 24 Times in 24 Posts
    Karen, I tried a couple of tests on Word 2010 and got the same results. Of course, when you run the recorded macro it makes no attempt to put anything in the footer, just puts in a paragraph marker and enters the "footer" on the next line.
    This is the "new and improved" Word???

Posting Permissions

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