Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using variables to print range of pages in VBA (Word 2003)

Status
Not open for further replies.

soLjd

Technical User
Jan 11, 2006
7
US
I have been working on this for a couple days and cannot figure it out!

Details: I have a large document that I need to separate and print by Technician names. I have working code that counts the # of pages for each technician and then calculates which pages to print, but I cannot get VBA to accept the variables (StartPage & EndPage) in the "Pages:=" property. I keep getting run-time error '5154': This is not a valid print range.

Here is my code:

Public Sub PrintForName()

StartPage = 1 ' these values are for testing only
EndPage = 2 ' StartPage/EndPage<= Global variables

Application.PrintOut FileName:="", _
Range:=wdPrintRangeOfPages,
Item:=wdPrintDocumentContent, _
Copies:=1, _
Pages:="& StartPage & - & EndPage &", _
PageType:=wdPrintAllPages, ManualDuplexPrint:=False, Collate:=True, Background:= _
True, PrintToFile:=False, PrintZoomColumn:=0, PrintZoomRow:=0, _
PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0



End Sub

I have experimented with this quite a bit and can't come up with the solution. Is using variables within this type of situation permissable? Any suggestions???
 


hi,
Code:
Pages:=StartPage & "-" & EndPage,

Skip,
[sub]
[glasses] [red]Be Advised![/red] The Vinyards of Texas have produced a wine with diuretic dimishment and urethric relief...
Pinot More![tongue][/sub]
 
Thanks Skip!
(I have to admit that I feel stupid.)
 
As a possible alternative, you could make bookmarks for each Technician then print the bookmark range. That way you would never have to actually determine the start and end pages for each. Just print the Technician range.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top