Code I used

Tech-Archive recommends: Fix windows errors by optimizing your registry



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.



.



Relevant Pages

  • Re: find files and open db
    ... If your folder names are in row 3, then this line needs to change: ... Dim myNames() As String ... Dim fCtr As Long ... Dim myFile As String ...
    (microsoft.public.excel.programming)
  • Re: Now in 2003, No code is highlighted..
    ... No dialogue box opens. ... What I want it to do is open all the files in the folder and save as the ... Dim FirstLoop As Boolean ...
    (microsoft.public.word.vba.general)
  • Now in 2003, No code is highlighted..
    ... No dialogue box opens. ... What I want it to do is open all the files in the folder and save as the ... Dim FirstLoop As Boolean ...
    (microsoft.public.word.vba.general)
  • Re: Finding and Replacing a Certain Word from 100+ Documents
    ... Dim FirstLoop As Boolean ... 'display dialog on first loop only ... Change the line above so it contains the folder where you have your ...
    (microsoft.public.word.vba.general)
  • Re: find files and open db
    ... Dim myNames() As String ... Dim fCtr As Long ... Dim myFile As String ... Here's one I saved that gets the files in a folder, opens each, hides some ...
    (microsoft.public.excel.programming)