Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    May 2002
    Location
    US
    Posts
    439
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word Macro Does Not function in W2000 (Word 97)

    To any and all,
    This is my first post to this forum. I have a situation where the attached file has a macro that partially functions in Word 2000. All of the macro works EXCEPT the find/replace in the header. The footer section works ok.

    The document is protected with the word TEST. Also, the macro works with the protection to turn it on and off at different times.

    Basically, I am asking for help in determining why the one section will not work.

    Any assistance is greatly appreciated.
    Attached Files Attached Files

  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

    Re: Word Macro Does Not function in W2000 (Word 97)

    Your code to open and search in the header is as follows:
    <pre>'Selects headers of document
    If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
    ActiveWindow.Panes(2).Close
    End If
    If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
    ActivePane.View.Type = wdOutlineView Or ActiveWindow.ActivePane.View.Type _
    = wdMasterView Then
    ActiveWindow.ActivePane.View.Type = wdPageView
    End If
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Selection.WholeStory

    ' Searches header of doc & replaces /A/ with Value1
    With Selection.Find
    .Text = Replace1
    .Replacement.Text = Value1
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll</pre>

    Possibly the problem is wdSeekCurrentPageHeader, since your first page has a different header that does not contain the Replace1 text? Not sure why it works for the footer, in that case.

    Whether or not that is the issue, you can manipulate headers and footer without using the View object. For example, consider this substitute code:
    <pre>Dim sect As Section, hdr As HeaderFooter
    For Each sect In ActiveDocument.Sections
    For Each hdr In sect.Headers
    With hdr.Range.Find
    .Text = "/A/"
    .Replacement.Text = "/B/"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
    End With
    Next
    Next</pre>

    Perhaps it takes a bit longer to check every header than to check just one, but if you want them all changed in the same way, this will do it. If you only want one changed, you can use a very specific parameter to drill down to, for example, the "regular" header in Section 2:

    Set myHeaderRange = ActiveDocument.Sections(2).Headers(wdHeaderFooterP rimary).Range

    and then manipulate myHeaderRange.Find

    Hope this helps.

  3. #3
    4 Star Lounger
    Join Date
    May 2002
    Location
    US
    Posts
    439
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Macro Does Not function in W2000 (Word 97)

    Thanks for the reply! I will edit the code and give it a try. I will reply back either way.

    Thanks again .

  4. #4
    4 Star Lounger
    Join Date
    May 2002
    Location
    US
    Posts
    439
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word Macro Does Not function in W2000 (Word 97)

    To :Jefferson Scher ,

    Thanks much for you assistance. You saved me hours of work.

    Your information fixed the issue,

    Brad

Posting Permissions

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