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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Macro Find Replace and save In Range of Files Help 1

Status
Not open for further replies.

autumnEND

Programmer
Nov 1, 2005
61
GB
Hi ive created a macro to search through a folder containing documents of a specific format, im wanting to search through these files and change a date within the files.

the document contains a release date Like :

Release Apr 06
but it could be :

Release May 06

so i need to search through the files for something like:

Release ???????

and once it finds the release date to replace the date to a set constant of "Release Jan 06"

here is part of the code :

'Replaces all release dates with the new date
With Selection.Find
.ClearFormatting
'We allow the replacement of 7 chrs
.Text = "Release ???????"
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchFuzzy = False
.MatchWildcards = True
If .Found = True Then
With .Replacement
.ClearFormatting
.Text = m_dateReplacement
End With
blnFoundReleaseDate = .Found
.Execute Replace:=wdReplaceAll, Wrap:=wdWrapAlways
End If
.Execute Format:=False, Forward:=True
End With

for some reason when it finds a date that needs to be changed, it wont change it.

it saves the new file into a new location but just wont change the date

any pointers would be greatly appreciated.

thanks
 
Hi autumnEND,

You are checking .Found before executing the Find so it is never True. Change
Code:
If .Found = True Then
to
Code:
If .Execute = True Then
The .Execute will return the result which is set in .Found.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top