Find & Replace

G

Gary

I am having a very interesting problem. I'm coding some VBA to do a global
Find and Replace. Below is the code that I'm using. It seems to work fine
except I won't do a Find & Replace in the Header or Footers. It works fine
on the rest of the document.

I'm using Access to code the VBA in and setting up a varaible list in a
table. Here is the code I'm using:



Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objDocs As Word.Documents
Dim NewName As String

Dim myDB As DAO.Database
Dim rsReplace As DAO.Recordset

NewName = "WorkCopy"


If Dir("D:\Development\Julian.Roberts\" & NewName & ".doc") <> "" Then

Kill "D:\Development\Julian.Roberts\" & NewName & ".doc"

End If

FileCopy "D:\Development\Julian.Roberts\GaryTest.doc",
"D:\Development\Julian.Roberts\" & NewName & ".doc"

Set myDB = CurrentDb
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("D:\Development\Julian.Roberts\" &
NewName & ".doc")

Set rsReplace = myDB.OpenRecordset("Select * from tblReplacementSetup")

If Not rsReplace.BOF Or Not rsReplace.EOF Then

rsReplace.MoveFirst

Do Until rsReplace.EOF

With objDoc.Content.Find
.ClearFormatting
With .Replacement
.ClearFormatting
End With
.Execute rsReplace!ReplacementSearchString, , , , , , , , ,
rsReplace!ReplaceWith, wdReplaceAll
End With



rsReplace.MoveNext

Loop

End If

rsReplace.Close
Set rsReplace = Nothing
myDB.Close
Set myDB = Nothing

objDoc.Save
objDoc.Close
Set objDoc = Nothing
objWord.Quit
Set objWord = Nothing


Does anyone have any idea as to why Find & Replace won't work in the Header
or Footers?

Thanks

Gary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top