Hi,
I need a macro that changes an active documents print settings for MS Word 97 so that the following is selected:
- 1 sided printing
- Page 1 Tray 1
- Page 2 Tray 2
- Page 3+ Tray 4
Is this possible?
thanks :thumb:
Printable View
Hi,
I need a macro that changes an active documents print settings for MS Word 97 so that the following is selected:
- 1 sided printing
- Page 1 Tray 1
- Page 2 Tray 2
- Page 3+ Tray 4
Is this possible?
thanks :thumb:
I know that you can use VBA code select the printer to use for a specific job, but to go beyond that and select particular features of the printer will probably require Windows API calls (?). At least I couldn't figure out any other way to do it. Maybe someone with API experience can help. You may have to repost this with "API" in the title.
thanks for the reply, haven't a clue what API is but have renamed the title!
I have found this sample code but it errors when it gets to ' .DefaultTray = "Tray 2"':
VB Code:
Dim sCurrentPrinter As String sCurrentPrinter = ActivePrinter wrd.ActivePrinter = "\\BTBEAPAPP03\PBTBEA00001M" wrd.With Options .DefaultTray = "Tray 2" End With Application.PrintOut FileName:="" wrd.With Options .DefaultTray = "Use printer settings" End With ActivePrinter = sCurrentPrinter
any suggestions?
thanks
Dont use the text property - "Tray 2"
VB Code:
'Const wdPrinterDefaultBin = 0 'Const wdPrinterUpperBin = 1 'Const wdPrinterLowerBin = 2 'Const wdPrinterMiddleBin = 3 'Const wdPrinterManualFeed = 4 Options.DefaultTrayID = wdPrinterUpperBin ActiveDocument.PrintOut
thanks for the reply,
I now have this:
VB Code:
Dim sCurrentPrinter As String sCurrentPrinter = ActivePrinter wrd.ActivePrinter = "\\BTBEAPAPP04\PBTBEA00004M" Const WdPrinterLowerbin = 2 wrd.Options.DefaultTrayID = WdPrinterLowerbin wrd.Application.PrintOut FileName:=""
however, it isn't selecting the tray.
Maybe I am along the wrong lines here. The problem is, the document when opened and printed automatically prints out on tray 1 for the first 2 pages, then tried to print the rest from the side feed but I can't figure out how to change this. When I go into print properties, it just has the paper source as auto so I think it has the print properties stored somewhere to default to the settings above?
thanks
Did you try the other constants I posted in my code? There are 15 different constants in all but these 5 are the most relevant.
wdPrinterDefaultBin
Or
wdPrinterManualFeed
thanks robdog, yeah, played abut and it seems to be working better, just need to figure which constants to use, we have big multifuntional printers with 4 trays and a side large bin, figured out the large side bin is wdPrinterLargeCapacityBin and got it printing from there. so, just a little playing about needed!
How can I get it now to only print page1 from one try, page 2 from another & the rest from another as the code I have prints it all from the same tray?
many thanks, I appreciate the help as this was driving me crazy :eek2:
:)VB Code:
Options.DefaultTrayID = wdPrinterLargeCapacityBin ActiveDocument.PrintOut , , Range:=wdPrintFromTo, From:=1, To:=1 Options.DefaultTrayID = wdPrinterLowerBin ActiveDocument.PrintOut , , Range:=wdPrintFromTo, From:=2, To:=2 Options.DefaultTrayID = wdPrinterUpperBin ActiveDocument.PrintOut , , Range:=wdPrintFromTo, From:=3, To:=5
RobDog ...
Where did you ever pick up all of this minutiae/trivia ??? Are you an escapee from Redmond?
I tried to rate your post (positively?) but the system is tired of my giving you credit.
:lol: No, but I think I will be going over there next year. I'll say hi to Bill for you.
I guess it just comes from the love of Office and automating it. I have learned over the years how the object library is all put together and what it mostly consists of so with a little searching I can find most stuff fast (if I dont remember it). Then its just testing what the poster needs solving and post to vbf. :D
Plus, I have many programs and utilities I have written over the years so I can usually pull some code or functions from them and create a sample. :)
thanks Robdog,
I've worked out what paper trays I need.
I'm now getting a run-time error on the line:
VB Code:
wrd.ActiveDocument.PrintOut , , Range:=wdPrintFromTo, From:=1, To:=1
Run-Time error '5148'
the number must be between -32765 and 32767
any ideas?
thanks alot
Oh, its because its not a range. Only a single page. There is another setting for that.
wdPrintCurrentPage
Then also try with double quotes around the page value.
VB Code:
Range:=wdPrintFromTo, From:="1", To:="3"
Robdog,
get the range error again for:
VB Code:
wrd.ActiveDocument.PrintOut , , Range:=wdPrintFromTo, _ From:="1", To:="2"
and for this wdPrintCurrentPage I get the same.
Maybe I should have mentioned I am opening word from excel, would this make a difference?
I recorded a macro in word to print the pages 1 & 2 and I get this:
[Highlight=VB]Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="1-2", PageType:= _
wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=FalseVBCODE]
could me alter this in anyway maybe?
thanks
For printing a range but I'm not sure about the parameter wdPrintAllPages for PageTypeVB Code:
wrd.ActiveDocument.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:=wdPrintDocumentContent, Copies:=1, Pages:="1-2", Background:=True, PrintToFile:=False