Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-19-2021, 01:34 AM
Gerrit Gerrit is offline DocumentBeforePrint doesnt work Windows 10 DocumentBeforePrint doesnt work Office 2019
Novice
DocumentBeforePrint doesnt work
 
Join Date: Feb 2021
Posts: 1
Gerrit is on a distinguished road
Angry DocumentBeforePrint doesnt work

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
Attached Images
File Type: jpg DocumentBeforePrint.JPG (60.6 KB, 22 views)
Reply With Quote
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
DocumentBeforePrint doesnt work Code doesnt work properly 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
DocumentBeforePrint doesnt work Command Button doesnt work on network rmw85 Word VBA 1 04-25-2012 01:02 PM
DocumentBeforePrint doesnt work My Product code doesnt work!!!! PLEASE HELP dukquaknoobhack Office 1 01-05-2012 03:43 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft