S
Stacey Bailey
We have recently changed our standard terminology and need to replace old
terms with new in a large number of documents (>400). Rather than doing
this manually or even one file at a time, I'd much rather create a listing
of the files that must be replaced and have a macro that automatically opens
each, performs the replacement, saves, and closes documents. (I think I
might be able to reuse this logic many many...many times in the future.)
However, I'm running into one snag. I can't get my Documents.Open to accept
a FileName represented by a variable rather than an explicit string. Below
is the code I'm working with, which errors out at the moment at
Documents.Open.
Can anyone help?
'Select first row in file listing file
While Selection.Text <> ""
MyFile = Trim(Selection.Text)
Selection.TypeBackspace 'Remove entry now that it has been read
Documents.Open FileName:=MyFile, ConfirmConversions _
:=False, ReadOnly:=False, AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto,
XMLTransform:=""
' Execute search and replace macro
'Save and close the file
Selection.MoveEnd Unit:=wdLine, Count:=1
Wend
Thanks,
Stacey Bailey
terms with new in a large number of documents (>400). Rather than doing
this manually or even one file at a time, I'd much rather create a listing
of the files that must be replaced and have a macro that automatically opens
each, performs the replacement, saves, and closes documents. (I think I
might be able to reuse this logic many many...many times in the future.)
However, I'm running into one snag. I can't get my Documents.Open to accept
a FileName represented by a variable rather than an explicit string. Below
is the code I'm working with, which errors out at the moment at
Documents.Open.
Can anyone help?
'Select first row in file listing file
While Selection.Text <> ""
MyFile = Trim(Selection.Text)
Selection.TypeBackspace 'Remove entry now that it has been read
Documents.Open FileName:=MyFile, ConfirmConversions _
:=False, ReadOnly:=False, AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto,
XMLTransform:=""
' Execute search and replace macro
'Save and close the file
Selection.MoveEnd Unit:=wdLine, Count:=1
Wend
Thanks,
Stacey Bailey