Microsoft Word Printing Macros
These are some simple Microsoft Word macros which print the current document to a particular tray of the chosen printer. The ‘printletters’ macro below is quite possibly the most useful script I have ever written. When my colleagues found out about this baby, they all demanded I set it up on their computers, and I became the hero of the workplace.
Well, that’s what I’d like to think, anyway.
I wrote these little macros to help diminish the annoyance of having to select the correct printer tray each time I wanted to print a document on a different kind of paper at work. When we send out letters to clients, we have to print the first page of their letter on letterhead and the remaining pages on plain white paper. We also have to print a file copy of the letter entirely on yellow paper.
This involves:
- Checking which tray the printer driver is currently set to print to, and changing it to letterhead, if it’s not already selected;
- Printing just the first page of the document (on letterhead);
- Changing the selected print tray to white;
- Printing the remainder of the document (on white)
- Changing the selected print tray to yellow;
- Printing the entire document again.
Which is a pretty annoying process, particularly if you’re writing lots of letters longer than one page in length.
Enter the macros. The first one deals with this situation, printing the whole document on yellow paper, then just the first page on letterhead, then the rest of the pages (if there are any more) on white paper. With just *one* click of a button, a single keystroke combination, or a wave of your magic wand, it is done.
Here it is:
Sub printletters()
'
' printletters Macro
'
'
Dim sCurrentPrinter As String
Dim sTray As Long
Dim TtlPgs As Integer
TtlPgs = Selection.Information(wdNumberOfPagesInDocument)
sCurrentPrinter = ActivePrinter
sTray = Options.DefaultTrayID
ActivePrinter = "PRINTER NAME"
With Options
.DefaultTrayID = "258" 'yellow
End With
Application.PrintOut FileName:="" 'print all
With Options
.DefaultTrayID = "259" 'letterhead
End With
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:="1" 'print just first page
If TtlPgs > 1 Then
With Options
.DefaultTrayID = "257" 'white
End With
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:="2-" & TtlPgs 'print remainder of pages
End If
With Options
.DefaultTrayID = sTray
End With
ActivePrinter = sCurrentPrinter
End Sub
Now if you want to use this macro, you’ll need to enter the name of the printer where it says “PRINTER NAME”. I’m sorry, I can’t tell you what it’s called, so you’ll need to figure that one out on your own.
Also – you’ll need to figure out what the default tray ID’s are too. Unfortunately I can’t remember how I figured out what mine are, I think I actually just guessed. In this case they are:
Tray 1 (white): 257
Tray 2 (yellow): 258
Tray 3 (letterhead): 259
If you have no idea what your tray ID’s are, I know there is a way of figuring it out, but I just don’t know what it is. I suggest you try Googling, or guessing like I did.
This next macro is for printing the entire current document to white paper only. I use this one when I need to print to white only, and can’t be bothered checking and changing which tray the printer is currently set to use.
Sub printwhite()
'
' print to white paper only
'
'
Dim sCurrentPrinter As String
Dim sTray As Long
'Dim TtlPgs As Integer
'TtlPgs = Selection.Information(wdNumberOfPagesInDocument)
sCurrentPrinter = ActivePrinter
sTray = Options.DefaultTrayID
ActivePrinter = "PRINTER NAME"
With Options
.DefaultTrayID = "257" 'white
End With
Application.PrintOut FileName:="" 'print all
With Options
.DefaultTrayID = sTray
End With
ActivePrinter = sCurrentPrinter
End Sub
And this last one is used for letters I don’t need a file copy of. It prints just the first page on letterhead, and the rest on white.
Sub printletterhead()
'
' prints first page to to letterhead, the rest on white
'
'
Dim sCurrentPrinter As String
Dim sTray As Long
Dim TtlPgs As Integer
TtlPgs = Selection.Information(wdNumberOfPagesInDocument)
sCurrentPrinter = ActivePrinter
sTray = Options.DefaultTrayID
ActivePrinter = "PRINTER NAME"
With Options
.DefaultTrayID = "259" 'letterhead
End With
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:="1" 'print just first page
If TtlPgs > 1 Then
With Options
.DefaultTrayID = "257" 'white
End With
ActiveDocument.PrintOut Range:=wdPrintRangeOfPages, Pages:="2-" & TtlPgs 'print remainder of pages
End If
With Options
.DefaultTrayID = sTray
End With
ActivePrinter = sCurrentPrinter
End Sub
