Loop thru files

M

Mickey

Hi,
I've done this before but seem to be doing something wrong now. I want
change the date in a bunch of docs.
I'm using the following code. It changes it in the first doc but doesn't
move to the next.

For Each aDoc In Documents

With Selection.Find
.Text = "01/29/07"
.Replacement.Text = "03/01/07"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.Execute Replace:=wdReplaceAll
End With

ActiveDocument.Save
ActiveDocument.Close
Next aDoc

Thanks,
Mickey
 
J

Jonathan West

Mickey said:
Hi,
I've done this before but seem to be doing something wrong now. I want
change the date in a bunch of docs.
I'm using the following code. It changes it in the first doc but doesn't
move to the next.

For Each aDoc In Documents

With Selection.Find
.Text = "01/29/07"
.Replacement.Text = "03/01/07"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.Execute Replace:=wdReplaceAll
End With

ActiveDocument.Save
ActiveDocument.Close
Next aDoc

Thanks,
Mickey

Change this

With Selection.Find

to this

With aDoc.Range.Find

and this

ActiveDocument.Save
ActiveDocument.Close

to this

aDoc.Save
aDoc.Close



--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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