• Word Macro Does Not function in W2000 (Word 97)

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Word Macro Does Not function in W2000 (Word 97)

    Author
    Topic
    #371845

    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.

    Viewing 0 reply threads
    Author
    Replies
    • #592316

      Your code to open and search in the header is as follows:

      '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

      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:

      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

      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(wdHeaderFooterPrimary).Range

      and then manipulate myHeaderRange.Find

      Hope this helps.

      • #592466

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

        Thanks again .

      • #592509

        To :Jefferson Scher ,

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

        Your information fixed the issue,

        Brad

    Viewing 0 reply threads
    Reply To: Word Macro Does Not function in W2000 (Word 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: