Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace portion of text in Footer

Status
Not open for further replies.

Jtorres13

Technical User
Nov 11, 2006
162
US
In thread707-1691129, you guys helped me find a portion of the footer (document number containing version number) and replace just the version number to the next number (increment), which worked fine until recently when we got the ability to delete versions. So now, a document can have multiple versions (1, 2, 3,etc.). But, since we can delete versions, a document can have versions (1, 3, 5, 6, 7, 11, etc.). I call this "version holes".

Because the macro increments the version number, if I have version 3 open and create a new version, the new version will be # 12, but the footer will say v4.

I would like to find and select the entire document number, including the version and replace it with the contents of another variable,strDocNum.

The syntax for our document numbers is as follows: ABC_XYZ: #1716153v2
<3 letters><underscore><3 letters><colon><space><hash tag><long integer><lowercase v><version number (integer between 0 - 99)>

I want to modify our macro to find the entire document number SLK_TAM: #1716153v2 and replace it with the new doc number that is stored in another variable.

I need to do this for all sections in the document and any possible types of footer (even, odd, first page, etc.).
 
You could simplify the previous macro's code to:
Code:
Sub UpdateFooters()
Dim Scn As Section, HdFt As HeaderFooter, i As Long
i = InputBox("What is the new version #?)
For Each Scn In ActiveDocument.Sections
  For Each HdFt In Scn.Footers
    If HdFt.LinkToPrevious = False Then
      With HdFt.Range
        With .Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .Format = False
          .Forward = True
          .Wrap = wdFindContinue
          .Text = "([0-9]{1,4}[Vv])[0-9]"
          .Replacement.Text = "\1" & i
          .MatchWildcards = True
          .Execute Replace:=wdReplaceAll
        End With
      End With
    End If
  Next HdFt
Next Scn
End Sub
unless, of course, your strDocNum is coming from somewhere else...

Cheers
Paul Edstein
[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top