Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-25-2018, 02:35 AM
Peltz Peltz is offline Execute VBA before printing Windows XP Execute VBA before printing Office 2003
Novice
Execute VBA before printing
 
Join Date: May 2015
Posts: 1
Peltz is on a distinguished road
Default Execute VBA before printing

Hello.

I'm trying to open a messagebox prompting a yes/no question when someone presses the print-icon in Word 2013.

This is the code I've written:

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)Dim Result As Long
Result = MsgBox("Text", vbYesNo)
If Result = vbNo Then
Exit Sub
Else


ActiveDocument.PrintOut
End If
End Sub
Sub FilePrintDefault()
Dim Result As Long
Result = MsgBox("Text", vbYesNo)
If Result = vbNo Then
Exit Sub
Else
ActiveDocument.PrintOut
End If
End Sub

However, I can't get the code to fire. Some input on how to get the code to fire would be much appreciated.

Thanks
Reply With Quote
  #2  
Old 01-26-2018, 09:38 PM
gmayor's Avatar
gmayor gmayor is offline Execute VBA before printing Windows 10 Execute VBA before printing Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You need two macros to intercept the Print commands in the document template e.g.

Code:
Sub FilePrintDefault()
Dim Result As Long
    Result = MsgBox("Text", vbYesNo)
    If Result = vbNo Then
        Exit Sub
    Else
        ActiveDocument.PrintOut
    End If
End Sub

Sub FilePrint()
Dim Result As Long
    Result = MsgBox("Text", vbYesNo)
    If Result = vbNo Then
        Exit Sub
    Else
        ActiveDocument.PrintOut
    End If
End Sub
However it will only work if the user has access to the template with the macros.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Execute VBA before printing Why does this Macro take so long to execute? poetofpiano Word VBA 3 09-30-2017 11:59 PM
Execute autocorrects? KaiserD2 Word 6 04-03-2017 10:18 PM
Execute VBA before printing Execute VBA on File Import npalmer610 Word VBA 1 04-12-2016 06:01 PM
Execute VBA before printing word 2010 mail merge execute twice smaddi Mail Merge 1 02-05-2012 02:45 AM
Execute VBA before printing Find and Execute cksm4 Word VBA 1 10-22-2011 11:36 PM

Other Forums: Access Forums

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


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