| TVP Print, automating page setup when printing from Word |
| Written by David Savery | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Wednesday, 31 March 2004 00:00 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Ideal for producing letters, but it just didn't work under Windows 2000. It took a lot of digging and experimenting but eventually I came up with a new default Word template which gave the users back this functionality and I document it here for anyone who may be in a similar position. Although I would like to blow my own trumpet, I can't take credit for the Visual Basic code that makes up this macro. For the most part the code and further information can be found at: http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=101 ...or... http://support.microsoft.com under knowledge base article 194789 (previously Q194789) Quick Links for those who don't want to scroll through my waffle: Download Normal.DOT containing the macro code Waffle commences...... Under Windows 95 most printer drivers adhered to Word default constants for the numbering and selection of paper trays as below:
With ActiveDocument.PageSetup Sadly, under Windows 2000, printer manufacturers have moved away from this list of constants to form their own proprietary lists which not only vary between manufacturers but also between models. This means if you have different printer models, there is no easy way of setting a document to print to selected trays without manually configuring the page setup before printing. This becomes a big problem for legacy applications which automatically mailmerge documents to the printer or for users who were used to running the old TVP Print macro which simply and easily split a document across two paper trays regardless of what printer was installed. If users want to keep their automatic printing functionality, a new macro is required which can sort out available paper trays for itself. Printers under Windows 2000 The list below shows the output values and names specified by a HP4100tn printer (left) and a HP4200tn printer (right) under Windows 2000. As you can see, both the names and numbers vary just between these similar models from the same manufacturer.
So, of all the multiple-tray printers Thames Valley Police have, each has its own naming/numbering convention. Under Word, each document's page setup can be manually configured to send the correct page to the correct tray as below:
This is achievable thanks to the new TVP Print macro which does the following: It interrogates the default printer driver to find the tray names and numbers; TVP Print can also: Create multiple copies of the printout if requested to by the user; All application servers have the TVP Print macros installed in their default Word template. Someone using this Word template will have toolbar buttons similar to those shown below:
The version window will tell you when the template was last updated. Pressing the TVP Print button or the CTRL-SHIFT-L keyboard shortcut will bring up the following dialogue box:
Adding new printers. TVP Print currently works with the following printers: Oki 24 (using DX driver) If a new multi-tray printer is purchased then install and configure it, run TVP Print and click the About button. TVP Print will report back the printer's available tray names/numbers similar to the example below taken from a HP 4200tn:
The Macros in Normal.DOT Entering the macro menu will show up the following macros with a description of their function below:
The Smiley and TVP Print buttons that have been added to the toolbar in Word point to the Version and TVPPrint macros respectively. When TVP Print is selected by either the CTRL-SHIFT-L keyboard sequence or by the user clicking on the button, the TVPPrint macro is executed. This macro calls two functions, GetBinNumbers and GetBinNames. Both macros interrogate the default printer driver to find the available tray numbers and names which are then inserted into an array. As different printers have varying amounts of available trays, the size of the array is set dynamically to match the amount of trays it sees. The array is then searched by an integer variable which runs through the retrieved tray numbers comparing them to known values. If a match is found then the macro knows the printer model it is talking to. An example of this working is with the 4100tn shown earlier. When interrogated by the GetBinNumbers function, the array will contain the numbers 7,4,1,2,11 and the numbers 16640-16650. Tray 3 has a value of 11 which is not used on any of the other multi-tray printers in Thames Valley Police, therefore when the array is searched, if the value 11 is found the macro assumes it is talking to a HP4100TN. Current "identifier" numbers configured within TVP Print are:
Any new multi-tray printers need to be tested for compatibility before being bought in bulk numbers. Once the TVP Print macro has identified the printer type it sets a string variable with the printer name and two integer variables called trayheaded and trayplain with the correct tray values to be used. It then calls up a userform called frmprint. This provides the user with the GUI interface. The printer model string variable is displayed and the userform awaits input from the user. Once a selection has been made the appropriate subroutine is called. The printing subroutines (SingleHeaded and OnePlusOne) convert the string variable of the required number of copies (as entered by the users but set to 1 by default) into an integer value which is used to run though a Do Until loop. As it runs through the loop it configures the page setup using the trayheaded and trayplain variables and prints out the document to those trays. Finally it configures the page setup back to how it was before the macro was run. The CTRLALTP and CTRLSHIFTP macros do the same thing but cut out the userform dialogue box. They each have keyboard shortcuts associated with them allowing the user to send a document to print with a minimum of input. For a full list of the code that makes up TVP Print click here. To download a zipped copy of Normal.DOT (version 3.7a) containing these macros along with its readme file and a Word file containing this information, click here. Maintenance and additions. If changes need to be made then increment the version numbers listed in the Version macro and the frmprint UserForm. The date of modification should also be entered in the Version macro. If adding printers, find the relevant tray codes (as described earlier) and edit the mPrint module in two places. Firstly, add a line to the array search similar to the 4200tn example below: If traytype = 1265 Then PrinterModel = "a HP4200tn" After the array search add related lines similar to the following: 'Set up trays for HP4200tn As stated earlier, each printer must have a tray number that is unique in order for TVP Print to correctly identify it. New printers must be vetted to ensure this is the case. Troubleshooting. HP4100 and HP4200 printers should be set up with the latest TN versions of the driver. The optional Tray3 paper source (if fitted) must be set in the driver on the server. This is the only option that should be changed on the server. On the printer itself tray 2 must be set as Plain and tray 3 must be set as Letterhead. Tally T9116D printers must be set up with a HP LaserJet IIIP driver if they are required to work with TVP Print. Oki 20+ Printers must be set up with the Oki 20+ driver, not the Oki 20n driver. When using TVP Print with a 4100TN printer, it should report back. Your printer is a 4100TN. If it reports back that your printer is a "Word Standard LaserJetIII/4100", check the driver on the server has been set up with the optional extra Tray 3. TVP Print currently supports only the following makes/models of printer: Tally T9116D using HP LJIIIP driver, HP4100/TN, HP4200TN, Oki20+, Oki24 (using dx driver). These are the only multi-tray printers currently in use by Thames Valley Police. If TVP Print throws up a "Runtime Error 9, Subscript out of range" error, then there is no default printer driver installed for it to interrogate. If the smiley face or TVP Print buttons are missing and it has been verified that the user is looking at the correct template, ensure that under View / Options both RG Toolbar and TVP Print are selected. TVP Print tries to apply a page setup to the whole document. If a document has section breaks then the page setup will apply to a single section causing TVP Print to function incorrectly. Remove section breaks from any multi-page document that is needed for use with TVP print. If TVP Print reports an "Error 5097 There is insufficient memory, Save the document now" then this is a problem between visual basic and the computers DCOM configuration. You can use DCOMCNFG to ensure Word has its identity set to "The Launching User", but it's likely that the workstation will require a reinstall of Word or a re-image. This fault may also manifest itself as a serious Word crash when the macro is run with a dialogue box requesting the user to send an error report to Microsoft. If you're having problems with an Oki24 (such as certain parts of a page not printing), disable Advanced Printing Features under the drivers Printing Preferences. If a printer insists on using the American Letter paper size, check the following three locations within the printer driver properties window are all set to A4: General / Printing Preferences / Advanced Advanced / Printing Defaults / Advanced Device Settings If TVP Print is not working as expected, test the configuration manually. Do this by opening Page Setup and set the document so that page one prints to the tray containing headed paper and subsequent pages print to the tray containing plain paper. Ensure page setup is applying the changes to the Whole Document and not a section (i.e. make sure there are no section breaks). Send the page to print. If it fails to print correctly then the fault is with the printer/driver setup rather than TVP Print (i.e. if you can't print it properly manually then you can't expect it to work when printed automatically). Try recording a macro while setting page setup to see which tray numbers the computer is using. Check the numbers to see if they are valid for your printer.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Last Updated on Saturday, 17 May 2008 12:03 |