Very Peculiar Macro/batch Problem!!!

N

notanoobreally

Hi all!!
here is this very very peculiar problem i am facing ... please help m
out!!... as my deadline is fast approaching and i ll be in a soup..
and this is such a problem that if explained to my boss.. he wont bu
it at all!!

now i have a bunch of 10000+ doc files..
i have to change every "on" with "in"(the font of in should be in Time
New Roman, my whole file is in Arial)..
now i dont want EVERY "on" to be changed into "in" i want only thos
occurences that are at the end of a word or standalone. For eg
"Qualification", "Deviation", "on" should change their "on" to "in" o
Times New Roman, but "only", "qualifications" should not. Anothe
example is the word "onion", only the "on" at the end of the wor
should be changed and not the one at the beginning...
now to accomplish this i used the following expression

"(on)>" - without the quotes

in the search and replace field.. alongwith the following cod
available on the word mvp site i.e.


Code
-------------------

Option Explicit
Public Sub BatchReplaceAll()
Dim FirstLoop As Boolean
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim Response As Long
PathToUse = "C:\Test\"
'Error handler to handle error generated whenever
'the FindReplace dialog is closed
On Error Resume Next
'Close all open documents before beginning
Documents.Close SaveChanges:=wdPromptToSaveChanges
'Boolean expression to test whether first loop
'This is used so that the FindReplace dialog will
'only be displayed for the first document
FirstLoop = True
'Set the directory and type of file to batch process
myFile = Dir$(PathToUse & "*.doc")
While myFile <> ""
'Open document
Set myDoc = Documents.Open(PathToUse & myFile)
If FirstLoop Then
'Display dialog on first loop only
Dialogs(wdDialogEditReplace).Show
FirstLoop = False
Response = MsgBox("Do you want to process " & _
"the rest of the files in this folder", vbYesNo)
If Response = vbNo Then Exit Sub
Else
'On subsequent loops (files), a ReplaceAll is
'executed with the original settings and without
'displaying the dialog box again
With Dialogs(wdDialogEditReplace)
.ReplaceAll = 1
.Execute
End With
End If
'Close the modified document after saving changes
myDoc.Close SaveChanges:=wdSaveChanges
'Next file in folder
myFile = Dir$()
Wend
End Sub

-------------------


Here is a screenshot of what i am doing
[image: http://www22.brinkster.com/totallylegal/search.jpg]

now after i press replace all.. it opens the first file in my workin
directory, in this case "C:\test\", and replaces all occurences.. the
when i close the replace dialog it asks that if i want to perform th
same action in all the files in the directory.. i say yes!.. it no
opens each and every doc file and replaces and saves..

so far so good!

cut 2:
after the long cumbersome process of opening and replacing and closin
10000+ doc files.. is finished with... i happily check a file.. to se
if it actually replaced the occurences ...
and what i see is that it has not done anything!!!!

i just fail to understand why this is happening!!
only a few files say around 10-15 of them are properly processed res
are as they were..

and yes, all the files opened up one by one.. but there was N
CHANGE!!.. i simply dont know what to do in such a situation.. !
please help..

so i tried to find something better...
googling i found ot Advanced Search and Replace..
now this is one good piece of software.. but the problem is that thoug
it does process doc files and replaces and searches with a busload o
tricks .. but it does not allow me to change the font formatting of th
particular replacement text!!

i am in a complete soup!
i showed the script to my boss, he was pretty happy with the level o
automation that had been created.. but now that very automation scrip
is doing everything, eating up time, cpu, everything.. but at the en
of the day it does not deliver the results!

please help!!
SOS


Regards
and lots of thanks in advance

ps: i checked for attributes.. of the docs.. none are read only.. i am
using word 2003, i tried this on word premium 2000 also!! but same
problem..
 
J

Jezebel

Curiosity will be the death of me nine times over. I'll solve the problem
for you if you'll just explain why on earth you need to do this. Go through
ten thousand documents (are they straw dogs?) and change 'tion' to 'tiin'
(etc), with a font change thrown in.

Please, please, explain. Does your boss have eight legs, and she eats her
lovers?





notanoobreally said:
Hi all!!
here is this very very peculiar problem i am facing ... please help me
out!!... as my deadline is fast approaching and i ll be in a soup...
and this is such a problem that if explained to my boss.. he wont buy
it at all!!

now i have a bunch of 10000+ doc files..
i have to change every "on" with "in"(the font of in should be in Times
New Roman, my whole file is in Arial)..
now i dont want EVERY "on" to be changed into "in" i want only those
occurences that are at the end of a word or standalone. For eg.
"Qualification", "Deviation", "on" should change their "on" to "in" of
Times New Roman, but "only", "qualifications" should not. Another
example is the word "onion", only the "on" at the end of the word
should be changed and not the one at the beginning...
now to accomplish this i used the following expression

"(on)>" - without the quotes

in the search and replace field.. alongwith the following code
available on the word mvp site i.e.


Code:
--------------------

Option Explicit
Public Sub BatchReplaceAll()
Dim FirstLoop As Boolean
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim Response As Long
PathToUse = "C:\Test\"
'Error handler to handle error generated whenever
'the FindReplace dialog is closed
On Error Resume Next
'Close all open documents before beginning
Documents.Close SaveChanges:=wdPromptToSaveChanges
'Boolean expression to test whether first loop
'This is used so that the FindReplace dialog will
'only be displayed for the first document
FirstLoop = True
'Set the directory and type of file to batch process
myFile = Dir$(PathToUse & "*.doc")
While myFile <> ""
'Open document
Set myDoc = Documents.Open(PathToUse & myFile)
If FirstLoop Then
'Display dialog on first loop only
Dialogs(wdDialogEditReplace).Show
FirstLoop = False
Response = MsgBox("Do you want to process " & _
"the rest of the files in this folder", vbYesNo)
If Response = vbNo Then Exit Sub
Else
'On subsequent loops (files), a ReplaceAll is
'executed with the original settings and without
'displaying the dialog box again
With Dialogs(wdDialogEditReplace)
.ReplaceAll = 1
.Execute
End With
End If
'Close the modified document after saving changes
myDoc.Close SaveChanges:=wdSaveChanges
'Next file in folder
myFile = Dir$()
Wend
End Sub

--------------------


Here is a screenshot of what i am doing
[image: http://www22.brinkster.com/totallylegal/search.jpg]

now after i press replace all.. it opens the first file in my working
directory, in this case "C:\test\", and replaces all occurences.. then
when i close the replace dialog it asks that if i want to perform the
same action in all the files in the directory.. i say yes!.. it now
opens each and every doc file and replaces and saves..

so far so good!

cut 2:
after the long cumbersome process of opening and replacing and closing
10000+ doc files.. is finished with... i happily check a file.. to see
if it actually replaced the occurences ...
and what i see is that it has not done anything!!!!

i just fail to understand why this is happening!!
only a few files say around 10-15 of them are properly processed rest
are as they were..

and yes, all the files opened up one by one.. but there was NO
CHANGE!!.. i simply dont know what to do in such a situation.. !!
please help..

so i tried to find something better...
googling i found ot Advanced Search and Replace..
now this is one good piece of software.. but the problem is that though
it does process doc files and replaces and searches with a busload of
tricks .. but it does not allow me to change the font formatting of the
particular replacement text!!

i am in a complete soup!
i showed the script to my boss, he was pretty happy with the level of
automation that had been created.. but now that very automation script
is doing everything, eating up time, cpu, everything.. but at the end
of the day it does not deliver the results!

please help!!
SOS


Regards
and lots of thanks in advance

ps: i checked for attributes.. of the docs.. none are read only.. i am
using word 2003, i tried this on word premium 2000 also!! but same
problem..
 
D

Doug Robbins - Word MVP

This is just the latest in a long series of such requests.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Jezebel said:
Curiosity will be the death of me nine times over. I'll solve the problem
for you if you'll just explain why on earth you need to do this. Go
through
ten thousand documents (are they straw dogs?) and change 'tion' to 'tiin'
(etc), with a font change thrown in.

Please, please, explain. Does your boss have eight legs, and she eats her
lovers?





notanoobreally said:
Hi all!!
here is this very very peculiar problem i am facing ... please help me
out!!... as my deadline is fast approaching and i ll be in a soup...
and this is such a problem that if explained to my boss.. he wont buy
it at all!!

now i have a bunch of 10000+ doc files..
i have to change every "on" with "in"(the font of in should be in Times
New Roman, my whole file is in Arial)..
now i dont want EVERY "on" to be changed into "in" i want only those
occurences that are at the end of a word or standalone. For eg.
"Qualification", "Deviation", "on" should change their "on" to "in" of
Times New Roman, but "only", "qualifications" should not. Another
example is the word "onion", only the "on" at the end of the word
should be changed and not the one at the beginning...
now to accomplish this i used the following expression

"(on)>" - without the quotes

in the search and replace field.. alongwith the following code
available on the word mvp site i.e.


Code:
--------------------

Option Explicit
Public Sub BatchReplaceAll()
Dim FirstLoop As Boolean
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim Response As Long
PathToUse = "C:\Test\"
'Error handler to handle error generated whenever
'the FindReplace dialog is closed
On Error Resume Next
'Close all open documents before beginning
Documents.Close SaveChanges:=wdPromptToSaveChanges
'Boolean expression to test whether first loop
'This is used so that the FindReplace dialog will
'only be displayed for the first document
FirstLoop = True
'Set the directory and type of file to batch process
myFile = Dir$(PathToUse & "*.doc")
While myFile <> ""
'Open document
Set myDoc = Documents.Open(PathToUse & myFile)
If FirstLoop Then
'Display dialog on first loop only
Dialogs(wdDialogEditReplace).Show
FirstLoop = False
Response = MsgBox("Do you want to process " & _
"the rest of the files in this folder", vbYesNo)
If Response = vbNo Then Exit Sub
Else
'On subsequent loops (files), a ReplaceAll is
'executed with the original settings and without
'displaying the dialog box again
With Dialogs(wdDialogEditReplace)
.ReplaceAll = 1
.Execute
End With
End If
'Close the modified document after saving changes
myDoc.Close SaveChanges:=wdSaveChanges
'Next file in folder
myFile = Dir$()
Wend
End Sub

--------------------


Here is a screenshot of what i am doing
[image: http://www22.brinkster.com/totallylegal/search.jpg]

now after i press replace all.. it opens the first file in my working
directory, in this case "C:\test\", and replaces all occurences.. then
when i close the replace dialog it asks that if i want to perform the
same action in all the files in the directory.. i say yes!.. it now
opens each and every doc file and replaces and saves..

so far so good!

cut 2:
after the long cumbersome process of opening and replacing and closing
10000+ doc files.. is finished with... i happily check a file.. to see
if it actually replaced the occurences ...
and what i see is that it has not done anything!!!!

i just fail to understand why this is happening!!
only a few files say around 10-15 of them are properly processed rest
are as they were..

and yes, all the files opened up one by one.. but there was NO
CHANGE!!.. i simply dont know what to do in such a situation.. !!
please help..

so i tried to find something better...
googling i found ot Advanced Search and Replace..
now this is one good piece of software.. but the problem is that though
it does process doc files and replaces and searches with a busload of
tricks .. but it does not allow me to change the font formatting of the
particular replacement text!!

i am in a complete soup!
i showed the script to my boss, he was pretty happy with the level of
automation that had been created.. but now that very automation script
is doing everything, eating up time, cpu, everything.. but at the end
of the day it does not deliver the results!

please help!!
SOS


Regards
and lots of thanks in advance

ps: i checked for attributes.. of the docs.. none are read only.. i am
using word 2003, i tried this on word premium 2000 also!! but same
problem..
 
P

Peter Hewett

Hi Doug Robbins - Word MVP

I'm going to give up writing code. I'm changing my name and posting anonymously
to some NG's I can think of instead!

Cheers - Peter

This is just the latest in a long series of such requests.

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
Jezebel said:
Curiosity will be the death of me nine times over. I'll solve the problem
for you if you'll just explain why on earth you need to do this. Go
through
ten thousand documents (are they straw dogs?) and change 'tion' to 'tiin'
(etc), with a font change thrown in.

Please, please, explain. Does your boss have eight legs, and she eats her
lovers?





notanoobreally said:
Hi all!!
here is this very very peculiar problem i am facing ... please help me
out!!... as my deadline is fast approaching and i ll be in a soup...
and this is such a problem that if explained to my boss.. he wont buy
it at all!!

now i have a bunch of 10000+ doc files..
i have to change every "on" with "in"(the font of in should be in Times
New Roman, my whole file is in Arial)..
now i dont want EVERY "on" to be changed into "in" i want only those
occurences that are at the end of a word or standalone. For eg.
"Qualification", "Deviation", "on" should change their "on" to "in" of
Times New Roman, but "only", "qualifications" should not. Another
example is the word "onion", only the "on" at the end of the word
should be changed and not the one at the beginning...
now to accomplish this i used the following expression

"(on)>" - without the quotes

in the search and replace field.. alongwith the following code
available on the word mvp site i.e.


Code:
--------------------

Option Explicit
Public Sub BatchReplaceAll()
Dim FirstLoop As Boolean
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim Response As Long
PathToUse = "C:\Test\"
'Error handler to handle error generated whenever
'the FindReplace dialog is closed
On Error Resume Next
'Close all open documents before beginning
Documents.Close SaveChanges:=wdPromptToSaveChanges
'Boolean expression to test whether first loop
'This is used so that the FindReplace dialog will
'only be displayed for the first document
FirstLoop = True
'Set the directory and type of file to batch process
myFile = Dir$(PathToUse & "*.doc")
While myFile <> ""
'Open document
Set myDoc = Documents.Open(PathToUse & myFile)
If FirstLoop Then
'Display dialog on first loop only
Dialogs(wdDialogEditReplace).Show
FirstLoop = False
Response = MsgBox("Do you want to process " & _
"the rest of the files in this folder", vbYesNo)
If Response = vbNo Then Exit Sub
Else
'On subsequent loops (files), a ReplaceAll is
'executed with the original settings and without
'displaying the dialog box again
With Dialogs(wdDialogEditReplace)
.ReplaceAll = 1
.Execute
End With
End If
'Close the modified document after saving changes
myDoc.Close SaveChanges:=wdSaveChanges
'Next file in folder
myFile = Dir$()
Wend
End Sub

--------------------


Here is a screenshot of what i am doing
[image: http://www22.brinkster.com/totallylegal/search.jpg]

now after i press replace all.. it opens the first file in my working
directory, in this case "C:\test\", and replaces all occurences.. then
when i close the replace dialog it asks that if i want to perform the
same action in all the files in the directory.. i say yes!.. it now
opens each and every doc file and replaces and saves..

so far so good!

cut 2:
after the long cumbersome process of opening and replacing and closing
10000+ doc files.. is finished with... i happily check a file.. to see
if it actually replaced the occurences ...
and what i see is that it has not done anything!!!!

i just fail to understand why this is happening!!
only a few files say around 10-15 of them are properly processed rest
are as they were..

and yes, all the files opened up one by one.. but there was NO
CHANGE!!.. i simply dont know what to do in such a situation.. !!
please help..

so i tried to find something better...
googling i found ot Advanced Search and Replace..
now this is one good piece of software.. but the problem is that though
it does process doc files and replaces and searches with a busload of
tricks .. but it does not allow me to change the font formatting of the
particular replacement text!!

i am in a complete soup!
i showed the script to my boss, he was pretty happy with the level of
automation that had been created.. but now that very automation script
is doing everything, eating up time, cpu, everything.. but at the end
of the day it does not deliver the results!

please help!!
SOS


Regards
and lots of thanks in advance

ps: i checked for attributes.. of the docs.. none are read only.. i am
using word 2003, i tried this on word premium 2000 also!! but same
problem..

HTH + Cheers - Peter
 

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