Macro run on entire folder of Word docs

R

Randy Faulkner

I think I've seen some pre-written utility to do this
somewhere??? Goal is to change the default printer tray
on about 500 docs.
 
P

Pete Bennett

This should do it for you... You'll need to change the tray settings as
these will be printer dependant.

Sub ChangeTrayMultipleDocs()
Dim sName As String
Dim aDoc As Document
Dim aSection As Section
Dim sDocsFolder As String

' disable screen updates to speed up processing
Application.Screenupdating = False

sDocsFolder = "C:\Folder With Documents In\"
sName = Dir(sDocsFolder & "*.doc")

While Len(sName) > 0
' Open the document by concantenating the folder name as Dir() won't return
the folder name
Set aDoc = Documents.Open(sDocsFolder & sName)
' Go through each section of the document (tray settings aren't document
properties)
For Each aSection In ActiveDocument.Sections
With aSection.PageSetup
.FirstPageTray = wdPrinterLowerBin
.OtherPagesTray = wdPrinterLowerBin
End With
Next aSection
aDoc.Save
aDoc.Close SaveChanges:=False
' Get the next file, if it returns an empty string, there are no more, so exit
sName = Dir
Wend

Application.Screenupdating = True

End Sub
 
Top