Code I used
- From: Janet A. Thompson <JanetA@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 11 Apr 2009 22:20:01 -0700
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 = "\server file path"
'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.SaveAs FileName:=Replace(myDoc.FullName, "BP#1", "")
myDoc.Close SaveChanges:=wdDoNotSaveChanges
'Next file in folder
myFile = Dir$()
Wend
End Sub
--
Janet A.
"Doug Robbins - Word MVP on news.microsof" wrote:
Show us the code of the macro that you have created..
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
"Janet A. Thompson" <JanetA@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:3E37AB36-06CC-454A-8FCB-B6D67E35F95D@xxxxxxxxxxxxxxxx
I did the two changes you directed. When I view my code (Alt +F11) and
look
in upper left corner box, I see I am "in" the New Module. I went Tools,
Customize in 2003 and pulled the macro up tothe toolbar. When I open the
doucment, I click on that and the screen goes totally blank.!!! with no
document open but the Word toolbar showing.
If I knew the basics of VB that would help. What mini course on VB is out
there or in Houston that I could take to get the basics down. What do you
think I am doing wrong above? Thanks!
--
Janet A.
"Janet A. Thompson" wrote:
I want my computer to open a folder , or if necessary I could be in that
folder, and for each file in the folder, go into the header text and
remove
the text SP-001, close the header, do a Save As and alter the existing
file
name so that the BP#1 is removed from the file name. The Save As could
save
it in the same or a different folder.
How to do?
Word 2003 XP, probably with the latest Service Pack
-- \
Janet A.
- Follow-Ups:
- Re: Code I used
- From: Doug Robbins - Word MVP on news.microsoft.com
- Re: Code I used
- References:
- How to do: Open folder, open each file, change header text, save a
- From: Janet A. Thompson
- RE: How to do: Open folder, open each file, change header text, save a
- From: Janet A. Thompson
- Re: How to do: Open folder, open each file, change header text, save a
- From: Doug Robbins - Word MVP on news.microsoft.com
- How to do: Open folder, open each file, change header text, save a
- Prev by Date: Re: Sending Word 2007 data to Excel 2007
- Next by Date: Re: VBA to shade a table row and insert value into 3rd column of t
- Previous by thread: Re: How to do: Open folder, open each file, change header text, save a
- Next by thread: Re: Code I used
- Index(es):
Relevant Pages
|