![]() |
#1
|
|||
|
|||
![]()
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 |
#2
|
||||
|
||||
![]()
The code I use for the BeforePrint event is an old Word MVP code detailed at
Intercepting events like Save and Print and Writing application event procedures While this code has been around since Word 2000, it is still valid today and works in the same Word version that you are using. Note that it doesn't fire until you click 'Print' on the File Print dialog
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
![]()
Message retracted. Code works for before print, changed implementation. Sorry.
__________________
Backup your original file before doing any modification. |
#4
|
||||
|
||||
![]()
The code in Graham's link still works. If it didn't work for you, the problem was with your implementation, not the code.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
Code works for before print, changed implementation. Thanks. Sorry.
I found that for the code to work each time it's changes or another event monitor is included, it is necessary to close and reopen Word.
__________________
Backup your original file before doing any modification. |
#6
|
||||
|
||||
![]()
You don't have to reopen Word, you can simply manually run the AutoExec macro again.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#7
|
|||
|
|||
![]()
You're right. Thanks!
__________________
Backup your original file before doing any modification. |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
ksigcajun | Word VBA | 6 | 04-06-2015 07:41 AM |
Powerpoint save as WMV but media doesnt work. | hooney | PowerPoint | 0 | 02-21-2013 09:45 PM |
Safe Senders Doesnt work | Anil Kaul | Outlook | 0 | 11-16-2012 01:28 PM |
![]() |
rmw85 | Word VBA | 1 | 04-25-2012 01:02 PM |
![]() |
dukquaknoobhack | Office | 1 | 01-05-2012 03:43 PM |