We have a 3rd party VBA module which we are tweaking to suit our needs. What we are trying to do is to search for a file path in the footer of a Word document, and replace the file path with a (3rd party generated) document ID.
The code is actually currently very straightforward and almost works. We have no problems overwriting the file path in the document footer with the required document ID, however currently our code is overwriting all text in the Word document footer (page number, initials of the person who wrote the document etc.) We just want the file path replaced.
Can anyone suggest where we're going wrong with the code below? The code currently searches for an existing ID; if it can't find that, but finds a file path it tries to overwrite; otherwise it writes the document ID to the document from scratch:
Set tSearch = doc.Sections(1).Footers(wdHeaderFooterPrimary).Range.Find
tSearch.Text = idStr
If Not tSearch.Execute() Then
'Current ID wasn't found; look for and replace an older one.
tSearch.MatchWildcards = True
tSearch.Text = "?:\*"
If Not tSearch.Execute(ReplaceWith:=idStr) Then
doc.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = False
doc.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text = idStr
doc.Sections(1).Footers(wdHeaderFooterPrimary).Range.Font.Size = 8
End If
End If