Re: Finding and Replacing a Certain Word from 100+ Documents
- From: "Greg Maxey" <gmaxey@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 25 Nov 2008 16:13:41 -0500
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
By the way, make a copy of your documents and work on the copy.
This is just in case the change goes horribly wrong and you
need to throw away the documents and start again. You still
have a set of originals in pristine condition, and you can
make another copy if necessary.
--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
--
Greg Maxey - Word MVP
My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
--
Greg Maxey - Word MVP
My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
.
- Follow-Ups:
- 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
- Finding and Replacing a Certain Word from 100+ Documents
- Prev by Date: Re: Finding and Replacing a Certain Word from 100+ Documents
- 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):
Relevant Pages
|