The Problem:
Changing the Compatibility settings in the Options dialog box so that I can legibly print a document that contains color text on my monochrome printer is getting kinda old. Automate it for me already!
The Solution:
Right you are. Create a macro that looks like Example 8-11.
This macro creates two Boolean variables, which are variables that can only be true
or False
. It then checks to see if the number of open documents is 0
; if so, it stops running the macro so as to avoid the error that results from trying to print without a document open.
Macro to print the active document in monochrome
Example 8-11.
Sub Print_Active_Document_in_Monochrome() Dim blnBWOn As Boolean Dim blnDocClean As Boolean If Documents.Count = 0 Then Exit Sub With ActiveDocument blnDocClean = .Saved blnBWOn = .Compatibility(wdPrintColBlack) .Compatibility(wdPrintColBlack) = True Dialogs(wdDialogFilePrint).Show .Compatibility(wdPrintColBlack) = blnBWOn .Saved = blnDocClean End With End Sub
For the bulk of its code, the macro uses a With
statement referring to the active document. It stores the current state of the document's Saved
property (TRue
if the document contains no unsaved changes, False
if it does contain some) in the blnDocClean
variable, and the state of the Compatibility (wdPrintColBlack)
setting (whether the "Print colors as black on noncolor printers" checkbox on the Compatibility tab of the Options dialog box is checked) in the blnBWOn
variable.
The macro then sets Compatibility(wdPrintColBlack)
to true
and displays the Print dialog box so that the user can print the document. Finally, the macro restores Compatibility(wdPrintColBlack)
and Saved
to the values stored in the two variables.