Script

G

George Spiro

Hi,

I am totally worthless in Scripting/VBS I am wondering if someone would be
able to but these 2 scripts togheter.

1st Script:

Public Sub BatchTEST2()

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:\Test\"

'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 = PathToUse
.SearchSubFolders = True
.FileName = "*.rtf"
.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

Script 2:

Sub GOODONE()
'
' GOODONE Macro
'
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientLandscape
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(11)
.PageHeight = InchesToPoints(8.5)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
Selection.WholeStory
Selection.Font.Name = "Courier New"
Selection.Font.Size = 8
End Sub

Option Explicit

Thanks alot,

George S.
 
H

Helmut Weber

Hi George,

I'd try it this way,
with lots of error handling possibly required,
and with a big warning, that a macro
which takes what to search for and what to replace with
from the previous search and replace operation,
and saves the doc (!), is a big danger.

Remove from Goodone all that isn't necessary.


Public Sub BatchTEST2()

Dim sPth As String ' the path
Dim sMsg As String ' the message
Dim lRsp As Long
Dim lCnt As Long

sPth = "C:\Test\"
sMsg = "Do you want to process " & _
"the rest of the files in this folder"
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If

With Application.FileSearch
.NewSearch
.LookIn = sPth
.SearchSubFolders = True
.FileName = "*.doc"
On Error Resume Next
If .Execute() Then
For lCnt = 1 To .FoundFiles.Count
Documents.Open (.FoundFiles(lCnt))
If lCnt = 1 Then
Dialogs(wdDialogEditReplace).Show
If MsgBox(sMsg, vbYesNo) = vbNo Then Exit Sub
Else
With Dialogs(wdDialogEditReplace)
.ReplaceAll = 1
.Execute
End With
End If
Goodone
ActiveDocument.Close SaveChanges:=wdSaveChanges
Next
End If
End With
End Sub

Sub Goodone()
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientLandscape
.TopMargin = InchesToPoints(0.5)
.BottomMargin = InchesToPoints(0.5)
.LeftMargin = InchesToPoints(0.5)
.RightMargin = InchesToPoints(0.5)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.5)
.FooterDistance = InchesToPoints(0.5)
.PageWidth = InchesToPoints(11)
.PageHeight = InchesToPoints(8.5)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
selection.WholeStory
selection.Font.Name = "Courier New"
selection.Font.Size = 8
End Sub

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
D

Doug Robbins - Word MVP

It's probably easier if you tell us what it is intended to do rather than
force us to have to deduce that by interpreting your code.

--
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top