Word

Remove Header Images Before Print

Ease of Use

Easy

Version tested with

2002 

Submitted by:

Jacob Hilderbrand

Description:

This macro offers the user the option of printing headers. It is set up to work for only a specified template. 

Discussion:

You have a template that has an image on the Header. For only documents based on this template, you want the user to be prompted with a message before they print. The message asks whether they want to print the header or not. You want it to run for any document that is created from a specific template. This is ideal for people who want to see the logo in their documents, but are printing onto pre-printed stationery. 

Code:

instructions for use

			

'In ThisDocument Option Explicit Dim oAppClass As New ThisApplication Private Sub Document_New() Set oAppClass.oApp = Word.Application End Sub 'In a Class Module 'Class Module must be named ThisApplication Option Explicit Public WithEvents oApp As Word.Application Private Sub oApp_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean) Dim MyTemplate As String Dim Remove As VbMsgBoxResult Application.ScreenUpdating = False Cancel = True MyTemplate = ActiveDocument.AttachedTemplate.Name If MyTemplate = "Doc1.dot" Then Remove = MsgBox("Do you want to print the logos?", vbQuestion + vbYesNo) If Remove = vbNo Then If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _ ActivePane.View.Type = wdOutlineView Then ActiveWindow.ActivePane.View.Type = wdPrintView End If ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader Selection.Find.ClearFormatting With Selection.Find .Text = "^g" End With Selection.Find.Execute Selection.Copy Selection.Delete Unit:=wdCharacter, Count:=1 ActiveDocument.PrintOut DoEvents Selection.Paste Application.CommandBars("Header and Footer").Visible = False DoEvents Else ActiveDocument.PrintOut End If End If Application.ScreenUpdating = True End Sub

How to use:

  1. Open Word.
  2. Press Alt + F11 to open VBE.
  3. Double Click ThisDocument from the Project Explorer.
  4. Paste the code from above that goes into ThisDocument.
  5. Select Insert Class Module.
  6. Rename the Class Module to ThisApplication from the Properties Window.
  7. Paste the code from above that goes in the Class Module.
  8. Close VBE (Press Alt + Q or press the X in the top right hand corner).
  9. Add a header to the Document.
  10. Save the Document as Doc1.dot (A Template, If you rename it you must change the name in the code).
  11. Close the Document.
  12. Create a New Document from the Doc1.dot template.
  13. Print.
  14. Select Yes to print the image, No to not print the image.
 

Test the code:

  1. Refer to the "How To Use" section.
  2. Download the attachment for an working example.
 

Sample File:

PrintModification.zip 15.51KB 

Approved by mdmackillop


This entry has been viewed 142 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express