Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2005

Tip: Looking for answers? Try searching our database.

Find & Replace

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gary - 12 Sep 2005 05:53 GMT
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
Helmut Weber - 12 Sep 2005 08:26 GMT
see:
http://word.mvps.org/FAQs/Customization/ReplaceAnywhere.htm

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
Gary - 12 Sep 2005 16:21 GMT
Thanks,  this looks like it will solve my problem.

Gary

> see:
> http://word.mvps.org/FAQs/Customization/ReplaceAnywhere.htm
[quoted text clipped - 3 lines]
> "red.sys" & chr(64) & "t-online.de"
> Word 2002, Windows 2000
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.