I am trying to capture Ctrl-P and the Print-button to redirect.
I have searched and found the following macro:
ThisDocument section:
Option Explicit
Public Sub AutoExec()
Register_Event_Handler
End Sub
Module1:
Option Explicit
Dim X As New EventClassModule
Sub Register_Event_Handler()
Set X.WordAppEvents = Word.Application
End Sub
EventClassModule:
Option Explicit
Public WithEvents WordAppEvents As Word.Application
Private Sub WordAppEvents_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
Cancel = True
' Run code directly inside this Sub OR
MsgBox "Before Print"
' Call another Sub here, note, Sub and Module name can't match
Cancel = False
End Sub
*************************************
The template, in which this macro is, is loaded automatically when starting Word. When I try to print, I would expect the messagebox, but this is not shown.
When I modify the EventClassModule:
Private Sub WordAppEvents_DocumentBeforePrint(ByVal Doc As Document, Cancel As Boolean)
to
Private Sub WordAppEvents__DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
The popup is shown.
It seems DocumentBeforePrint has a problem. I am using Word version 2101 (build 13628.20380 Click-and-Run)
Anyone who can help me get this working?
Thanks in advance for your response.
Gerrit