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
 

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