Word 2003 hangs while running this macro

J

Joe Williams

I've been trying to use this macro (from WordTips)to change my email
address in all the documents in a folder. However, whenever I try to
run it, Word just goes into hourglass-forever mode, and I have to
ctl-alt-del my way out of the program. I don't know much about macros
and have basically cut-and-pasted this into my normal.dot document
which has a couple of other macros that work. Is there something
obviously wrong with this particular macro, or is it just that, as
usual, I don't know what I'm doing?

Thanks for any guidance. Here's the macro:


Public Sub MassReplace()
With Application.FileSearch
.LookIn = "C:\" ' where to search
.SearchSubFolders = True ' search the subfolders
.FileName = "*.doc" ' file pattern to match

' if more than one match, execute the following code
If .Execute() > 0 Then
' for each file you find, run this loop
For i = 1 To .FoundFiles.Count
' open the file based on its index position
Documents.Open FileName:=.FoundFiles(i)

' search and replace the address
selection.Find.ClearFormatting
selection.Find.Replacement.ClearFormatting
With selection.Find
.Text = "OldAddress"
.MatchCase = True
.Replacement.Text = "NewAddress"
End With
selection.Find.Execute Replace:=wdReplaceAll

' replace e-mail address
With selection.Find
.Text = "Oldemail"
.Replacement.Text = "Newemail"
End With
selection.Find.Execute Replace:=wdReplaceAll

' save and close the current document
ActiveDocument.Close wdSaveChanges
Next i
Else
' if the system cannot find any files
' with the .doc extension
MsgBox "No files found."
End If
End With
End Sub
 
J

Jonathan West

if you are looking in the C:\ folder and searching subfolders, then the
search might take quite a long time. I'd suggest you try on another folder
with a smaller number of files in it, and see if the macro works there.

Then set the Lookin pproperty to the folder that contains most of your Word
documents, and run it there.

Of course, you *have* taken a backup in case something goes wrong with this
batch conversion?
 

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