PDA

Click to See Complete Forum and Search --> : Print settings - API?


rocket0612
Mar 6th, 2006, 11:13 AM
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:

Webtest
Mar 6th, 2006, 01:18 PM
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.

rocket0612
Mar 6th, 2006, 01:46 PM
thanks for the reply, haven't a clue what API is but have renamed the title!

rocket0612
Mar 7th, 2006, 02:41 AM
I have found this sample code but it errors when it gets to ' .DefaultTray = "Tray 2"':


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

RobDog888
Mar 7th, 2006, 03:37 AM
Dont use the text property - "Tray 2"
'Const wdPrinterDefaultBin = 0
'Const wdPrinterUpperBin = 1
'Const wdPrinterLowerBin = 2
'Const wdPrinterMiddleBin = 3
'Const wdPrinterManualFeed = 4
Options.DefaultTrayID = wdPrinterUpperBin
ActiveDocument.PrintOut

rocket0612
Mar 7th, 2006, 05:26 AM
thanks for the reply,

I now have this:


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

RobDog888
Mar 7th, 2006, 07:42 AM
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

rocket0612
Mar 7th, 2006, 08:35 AM
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:

RobDog888
Mar 7th, 2006, 09:00 AM
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:)

Webtest
Mar 7th, 2006, 10:20 AM
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.

RobDog888
Mar 7th, 2006, 10:36 AM
: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. :)

rocket0612
Mar 7th, 2006, 11:44 AM
thanks Robdog,

I've worked out what paper trays I need.

I'm now getting a run-time error on the line:

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

RobDog888
Mar 7th, 2006, 12:01 PM
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.
Range:=wdPrintFromTo, From:="1", To:="3"

rocket0612
Mar 8th, 2006, 04:59 AM
Robdog,

get the range error again for:


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

RobDog888
Mar 8th, 2006, 05:06 AM
wrd.ActiveDocument.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:=wdPrintDocumentContent, Copies:=1, Pages:="1-2", Background:=True, PrintToFile:=FalseFor printing a range but I'm not sure about the parameter wdPrintAllPages for PageType