Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Marilyn <Marilyn@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 26 Nov 2008 05:53:01 -0800
Good Morning Greg,
Beautiful Work......I tried it and I love the message you get when clicking
the Cancel button. I've always wanted to learn more about macros and
programming, but..... :-(
Once again you did an outstanding job with the code and sharing it with all
of us. Write back if you get a chance and let me know what books I can pick
up on VBA in MS Word.
Thanks
"Greg Maxey" wrote:
Actually it was easier than I thought. Try downloading the AddIns again..
Marilyn wrote:
Ah yes... Now I get a prompt to enter password. You sir are a
genius.... :-) Here's something to ponder. What is the person did
not know the password, can clicking the Cancel button tell the
program to skip that file and move on to the next. Perhaps the code
can skip all password protected file and in the end let the user know
x amount of files were skipped due to password constraints.
Thanks a bunch for sharing your code with all of us.
"Greg Maxey" wrote:
OK, I think I have that fixed try downloading the AddIns again.
Marilyn wrote:
That is correct. The word document requires a password to unprotect
the form fields.
"Greg Maxey" wrote:
Marilyn,
So you mean the form is both protected and requires a password to
unprotect. Right?
In that case, yes it will fail as you indicate.
Marilyn wrote:
Hi Greg,
I re-downloaded the template and tried it again but I still get
the following error:
Run-time error '5485': The Password is incorrect.
The file it stops in is a Word form and the Form fields are
password protected.
Thanks,
"Greg Maxey" wrote:
Marilyn,
That shouldn't happen. I just reloaded the AddIns from my files
at home to the web page. I don't have any issues with protected
forms.
http://gregmaxey.mvps.org/Process_Batch_Folder.htm
Marilyn wrote:
Hi Greg,
I tried your add-in on one of the folders and it worked great!
the only problem I ran into is that some of the documents are
protected forms, and when the code encounters a protected file
it stops. My way around this is to unprotect those files for
the process to run.
Graham, initially the link did not work for me, but I finally
got it to open the page..... Thanks for your help as well.
"Greg Maxey" wrote:
Or see:
http://gregmaxey.mvps.org/Process_Batch_Folder.htm
--
Greg Maxey - Word MVP
My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
"Marilyn" <Marilyn@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5E20927F-6B51-4BBF-BB55-87533AF7F83E@xxxxxxxxxxxxxxxx
Hello Graham,
The link appears to be broken.
"Graham Mayor" wrote:
You may find http://www.gmayor.com/batch_replace.htm easier
to understand -
and see the link there to Greg Maxeyt's add-in.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Marilyn wrote:
Hello,
Thanks again.... I'm not a macro expert so I'm having a
tough time getting the macro to work. I looked over the
site again and figured the second macro would work best.
Once again I'm making the changes I think I need to make
based on the location of my files, but It does not work.
Please let me know what I'm doing wrong.... Thanks.... PS:
Yes, I had already created a copy of the files to work with.
Below is the second code with the changes that I made.
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
Dim i As Long
PathToUse = "C:\policies\admissions"
'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
With Application.FileSearch
.NewSearch
.LookIn = "c:\policies\admissions"
.SearchSubFolders = True
.FileName = "*.doc"
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
If .Execute() Then
For i = 1 To .FoundFiles.Count
'Open document
Set myDoc = Documents.Open(.FoundFiles(i))
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 i
End If
End With
End Sub
Thanks,
"Jonathan West" wrote:
"Marilyn" <Marilyn@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message
news:3BE6610C-0F15-4394-8B05-E9758EE1AA77@xxxxxxxxxxxxxxxx
Hi Jonathan,
Thank you so much for the quick response. I reviewed the
code, but I'm not
sure which lines I'm supposed to change. Would you be
able to point me in the right direction once again.
Here's the code from the site.
Required changes are indicated inline
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\"
Change the line above so it contains the folder where you
have your documents. Make sure you include the \ character
at the end.
'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")
Change the line above to this, because you are using Word
2007 documents
myFile = Dir$(PathToUse & "*.docx")
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
- Follow-Ups:
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Greg Maxey
- Re: Finding and Replacing a Certain Word from 100+ Documents
- References:
- Finding and Replacing a Certain Word from 100+ Documents
- From: Marilyn
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Jonathan West
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Marilyn
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Jonathan West
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Marilyn
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Graham Mayor
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Marilyn
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Greg Maxey
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Marilyn
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Greg Maxey
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Marilyn
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Greg Maxey
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Marilyn
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Greg Maxey
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Marilyn
- Re: Finding and Replacing a Certain Word from 100+ Documents
- From: Greg Maxey
- Finding and Replacing a Certain Word from 100+ Documents
- Prev by Date: Re: MailMerge to Document Dialog Box
- Next by Date: Re: Finding and Replacing a Certain Word from 100+ Documents
- Previous by thread: Re: Finding and Replacing a Certain Word from 100+ Documents
- Next by thread: Re: Finding and Replacing a Certain Word from 100+ Documents
- Index(es):