Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 06-08-2016, 09:01 PM
gmayor's Avatar
gmayor gmayor is offline DocumentBeforePrint for One Document Only Windows 10 DocumentBeforePrint for One Document Only Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
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 ofgmayor has much to be proud of
Default

This is relatively straightforward. Add a class module to the document call it EventClassModule
In that module put the following example code. Edit it to reflect your check boxes and the message you wish to convey
Code:
Option Explicit
Public WithEvents appWord As Word.Application

Private Sub appWord_DocumentBeforePrint _
        (ByVal Doc As Document, _
         Cancel As Boolean)
Dim intResponse As Integer
Dim sBox As String

    Select Case False
        Case ThisDocument.CheckBox1.Value: sBox = "CheckBox 1"
        Case ThisDocument.CheckBox2.Value: sBox = "CheckBox 2"
        Case ThisDocument.CheckBox3.Value: sBox = "CheckBox 3"
    End Select


    intResponse = MsgBox(sBox & " has not been checked!", _
                         vbOKCancel)
    If intResponse = vbCancel Then Cancel = True
End Sub
Add an ordinary module to the document and add the following code
Code:
Option Explicit
Dim X As New EventClassModule
Sub AutoOpen()
    Register_Event_Handler
End Sub
Sub Register_Event_Handler()
    Set X.appWord = Word.Application
End Sub
Save the document as a macro enabled document. When the document is opened the autoopen macro runs and sets the event handler. (You can run it from the module for testing).
__________________
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
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
DocumentBeforePrint for One Document Only split word document based on bookmarks with each new document title of the bookmark megatronixs Word VBA 9 09-05-2020 02:29 PM
Adding a link into a word document that when pressed, takes user to a page within the same document yan89 Word 1 04-29-2016 01:54 PM
Vba code to save document as pdf using document property text and rename folder. staicumihai Word VBA 1 12-21-2015 07:39 AM
DocumentBeforePrint for One Document Only Run-time error '1004': Document not saved. The document may be open... doctor_who12 Excel Programming 1 01-22-2014 04:47 PM
DocumentBeforePrint not working maruapo Drawing and Graphics 0 06-15-2010 12:31 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:57 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