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