Problem with ActiveDocument.PageSetup

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
 
D

Doug Robbins - Word MVP

How do you know that 260 is the correct number for the paper tray that you
want to use?

Controlling the Printer from Word VBA
Part 1: Using VBA to Select the Paper Tray
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=101


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

stevewy

I got the FirstPageTray value by recording myself changing to the
letterheaded
tray on the same printer, then viewing the resulting macro. So Word
itself decided that this was the correct number.

I should point out that I'm doing this at work, and the macro in its
entirely does work on my PC, but it gives the stated error message
when run on a colleague's PC. However, the macro was constructed on
his PC (I mean that I got the FirstPageTray values from his PC, not
mine), so I am at a loss as to why it will work on mine but not his.
I am running Word 2003, and he is running Word 2000 - but surely this
macro should work on both versions, since I cannot see any "unique"
Word 2003 VBA commands here.

Please note my original message comment that "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".

Is there something else on my colleague's PC that could be different
than mine, which would stop the macro from running and produce this
error? He has no other problems printing - and no problem selecting
the paper trays by recording a macro of changing the trays, then
playing it back on its own. It's just when it's part of this macro...

Steve
 

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