S
stevewy
I'm trying to construct a macro that would open up each document in a
directory, then print out all odd pages from one printer tray
(containing letterheaded paper), then switch paper trays and print out
all even numbered pages (on plain). Then close the document and move
on to the next one in the directory, till all documents had been
printed.
I am having trouble because the macro stops with "Value out of range -
run-time error 4608" whenever it reaches:
With ActiveDocument.PageSetup
.FirstPageTray = 260
in the code below. Does anyone have any idea why? I got the
FirstPageTray value by recording myself changing to the letterheaded
tray on the same printer, then viewing the resulting macro. I also
tried the macro on an already-open document, removing the lines that
auto-open documents, but still got the same error. So, I figure, it
cannot be a problem with Word not regarding the just-opened document
as the "Active" one. The macro does not stop on the
ActiveDocument.PageSetup line, but the .FirstPageTray = 260 one. I
put another (meaningless) margin command just before .FirstPageTray
and it stopped on that too. So it seems to have a problem with the
first command after "With ActiveDocument.PageSetup".
Any ideas? Thank you for any help you can give.
Steve Wylie
Sub MassPrint()
With Application.FileSearch
.LookIn = "c:\sample" ' where to search
.SearchSubFolders = True ' search the subfolders
.FileName = "*.doc" ' file pattern to match
' if more than one match, execute the following code
If .Execute() > 0 Then
' to display how many files this macro will access,
' uncomment the next line of code
MsgBox "Found " & .FoundFiles.Count & " file(s)."
' for each file you find, run this loop
For i = 1 To .FoundFiles.Count
' open the file based on its index position
Documents.Open FileName:=.FoundFiles(i)
' change to letterheaded tray
With ActiveDocument.PageSetup
.FirstPageTray = 260
.OtherPagesTray = 260
End With
Application.PrintOut FileName:="", Range:=wdPrintAllDocument,
Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:= _
wdPrintOddPagesOnly, ManualDuplexPrint:=False, Collate:=True,
Background _
:=False, PrintToFile:=False
'change to plain tray
With ActiveDocument.PageSetup
.FirstPageTray = 262
.OtherPagesTray = 262
End With
Application.PrintOut FileName:="", Range:=wdPrintAllDocument,
Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:= _
wdPrintEvenPagesOnly, ManualDuplexPrint:=False, Collate:=True,
Background _
:=False, PrintToFile:=False
' save and close the current document
ActiveDocument.Close wdDoNotSaveChanges
Next i
Else
' if the system cannot find any files
' with the .doc extension
MsgBox "No files found."
End If
End With
End Sub
directory, then print out all odd pages from one printer tray
(containing letterheaded paper), then switch paper trays and print out
all even numbered pages (on plain). Then close the document and move
on to the next one in the directory, till all documents had been
printed.
I am having trouble because the macro stops with "Value out of range -
run-time error 4608" whenever it reaches:
With ActiveDocument.PageSetup
.FirstPageTray = 260
in the code below. Does anyone have any idea why? I got the
FirstPageTray value by recording myself changing to the letterheaded
tray on the same printer, then viewing the resulting macro. I also
tried the macro on an already-open document, removing the lines that
auto-open documents, but still got the same error. So, I figure, it
cannot be a problem with Word not regarding the just-opened document
as the "Active" one. The macro does not stop on the
ActiveDocument.PageSetup line, but the .FirstPageTray = 260 one. I
put another (meaningless) margin command just before .FirstPageTray
and it stopped on that too. So it seems to have a problem with the
first command after "With ActiveDocument.PageSetup".
Any ideas? Thank you for any help you can give.
Steve Wylie
Sub MassPrint()
With Application.FileSearch
.LookIn = "c:\sample" ' where to search
.SearchSubFolders = True ' search the subfolders
.FileName = "*.doc" ' file pattern to match
' if more than one match, execute the following code
If .Execute() > 0 Then
' to display how many files this macro will access,
' uncomment the next line of code
MsgBox "Found " & .FoundFiles.Count & " file(s)."
' for each file you find, run this loop
For i = 1 To .FoundFiles.Count
' open the file based on its index position
Documents.Open FileName:=.FoundFiles(i)
' change to letterheaded tray
With ActiveDocument.PageSetup
.FirstPageTray = 260
.OtherPagesTray = 260
End With
Application.PrintOut FileName:="", Range:=wdPrintAllDocument,
Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:= _
wdPrintOddPagesOnly, ManualDuplexPrint:=False, Collate:=True,
Background _
:=False, PrintToFile:=False
'change to plain tray
With ActiveDocument.PageSetup
.FirstPageTray = 262
.OtherPagesTray = 262
End With
Application.PrintOut FileName:="", Range:=wdPrintAllDocument,
Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:= _
wdPrintEvenPagesOnly, ManualDuplexPrint:=False, Collate:=True,
Background _
:=False, PrintToFile:=False
' save and close the current document
ActiveDocument.Close wdDoNotSaveChanges
Next i
Else
' if the system cannot find any files
' with the .doc extension
MsgBox "No files found."
End If
End With
End Sub