See the code at http://www.gmayor.com/batch_replace.htm
Add the line
Dim intPos As Integer
at the start of
Public Sub BatchReplaceAnywhere()
Replace in that sub
'Close the file, saving the changes.
myDoc.Close Savechanges:=wdSaveChanges
myFile = Dir$()
Wend
End Sub
with
intPos = InStrRev(myFile, ".")
myFile = Left(myFile, intPos - 1)
myFile = myFile & "_MOD.txt"
MyDoc.SaveAs FileName:=myFile, _
FileFormat:=wdFormatDOSText
MyDoc.Close SaveChanges:=wdDoNotSaveChanges
myFile = Dir$()
Wend
End Sub
This should leave your original files unchanged but save new text versions
with the filename
filename_MOD.txt in the same folder. Test on sample data.

Signature
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Dear all,
>
[quoted text clipped - 15 lines]
> - 009
> http://en.wikipedia.org/wiki/Cyborg_009
Excel 009 - 18 Oct 2006 20:17 GMT
Thank you Graham.
You code works after I did the following changes:
Comment out:
'Close any documents that may be open
' If Documents.Count > 0 Then
' Documents.Close SaveChanges:=wdPromptToSaveChanges
' End If
Because it closes my Word document that contains the macro.
Change
myFile = Dir$(PathToUse & "*.doc")
to
myFile = Dir$(PathToUse & "*.txt")
because my files are txt files.
I code ran, but where are the output files? Where are they located?
- 009
Russ - 19 Oct 2006 04:49 GMT
Excel 009,
> Thank you Graham.
>
[quoted text clipped - 17 lines]
>
> I code ran, but where are the output files? Where are they located?
Did you check your original files to see if they where changed after
'running code'?
> - 009

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Russ - 19 Oct 2006 04:57 GMT
Excel 009,
> Excel 009,
>
[quoted text clipped - 21 lines]
> Did you check your original files to see if they *where typo* changed after
> 'running code'?
I meant, did original files change, like you wanted them to change?
>> - 009

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Graham Mayor - 19 Oct 2006 07:23 GMT
Put the macro in normal.dot - not the document you are working with and
restore the commented lines.
Your other changes seem OK - but for some reason I am not yet clear about,
the modified documents are saved in the default document folder (tools >
options > file locations > documents).
You'll also need to ensure that tools > options > general > confirm
conversions at open is unchecked or you will be prompted for a text filter
for each document in the folder.

Signature
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Thank you Graham.
>
[quoted text clipped - 19 lines]
>
> - 009
Excel 009 - 19 Oct 2006 14:13 GMT
Hi Graham and Russ,
Yes, the output files got populated beautifully. Thanks to Graham's
code.
It was my mistake that despite I listed the changes that I did, but the
changes were not saved and the code was ran unchanged.
I have another question. How can I have the have the whole word
changed and not on partial work. Ex: in
x = 10
text = "ABC"
z = x + 30,
if I want to just change the "x" variable to "y" without making change
on "text", how can I do so?
- 009
Graham Mayor - 19 Oct 2006 15:47 GMT
You will have to include sufficient of the string to uniquely identify it,
eg search for
z = x + 30
replace with
z = y + 30
If necessary change the line
.MatchWildcards = False
to
.MatchWildcards = True
and use a suitable wildcard pattern
http://www.gmayor.com/replace_using_wildcards.htm

Signature
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Hi Graham and Russ,
>
[quoted text clipped - 14 lines]
>
> - 009
Excel 009 - 19 Oct 2006 16:02 GMT
Ok, Thanks. I think including the space after will help.
-009
Tony Jollans - 19 Oct 2006 17:58 GMT
The easiest wildcard pattern for your example would be <x> which means
start-of-word lower-case-letter-x end-of-word
--
Enjoy,
Tony
> You will have to include sufficient of the string to uniquely identify it,
> eg search for
[quoted text clipped - 35 lines]
> >
> > - 009