Using VBA to remove header & footer before printing (1 Viewer)

shenty

Registered User.
Local time
Today, 00:57
Joined
Jun 8, 2007
Messages
119
I have aquired some VBA that gives me the option to remove headers from a word document prior to printing. The is because sometimes i want to print to PDF using the header logo already in my document template, yet other times i want to print to our preprinted letterheaded paper.

It works OK but i would like it to remove footers as well as headers.

Could anyone guide me in altering this code to suit.

Many thanks

Code:
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 = "Quotation Template header option.dot" Then
        Remove = MsgBox("Do you want to print the header/footer 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
 

Users who are viewing this thread

Top Bottom