Re: Code I used

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I would think that your main problem is that

PathToUse = "\server file path"

will not return anything useful.

If you replace that with

Dim fd as FileDialog

Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.Title = "Select the folder containing the files."
If .Show = -1 Then
PathToUse = .SelectedItems(1) & "\"
Else
End If
End With

then when you run the code, a dialog box will open that you can use to
navigate to the folder that contains the files.

--
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:FB68ABFD-AECE-4C7F-8741-EA9DD536B4F1@xxxxxxxxxxxxxxxx
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: yellow highlight over first line of code name
    ... editor opens showing a yellow highlight over the first line of the vb ... Janet A. ... navigate to the folder that contains the files. ... Dim FirstLoop As Boolean ...
    (microsoft.public.word.vba.general)
  • Re: yellow highlight over first line of code name
    ... editor opens showing a yellow highlight over the first line of the vb name. ... Janet A. ... navigate to the folder that contains the files. ... Dim FirstLoop As Boolean ...
    (microsoft.public.word.vba.general)
  • Re: Execute macro for all documents in the folder
    ... It is simple enough to batch process a single folder. ... Dim strFileName As String ... It seems as though the below macro from an earlier posting was put ...
    (microsoft.public.word.docmanagement)
  • Re: Execute macro for all documents in the folder
    ... It is simple enough to batch process a single folder. ... Dim strFileName As String ... It seems as though the below macro from an earlier posting was put ...
    (microsoft.public.word.docmanagement)
  • Re: HTML Item properties vs. Regular item properties
    ... I don't use the MSN provider, but AFAIK the date in the default store's is ... OutlookSpy - Outlook, CDO ... as well as the Sent Items folder on the MSN server. ... Dim app As Outlook.Application ...
    (microsoft.public.outlook.program_vba)