#1
|
|||
|
|||
Message Box on Close
Hi All,
I have the following code which works great. However, I want to adapt it so if the message box is clicked 'No' Then the document DOES NOT close. Is this possible? Thanks Code:
Private Sub Document_Close() Dim orng As Word.Range Dim ofld As FormFields Set orng = ActiveDocument.Range Set ofld = orng.FormFields For i = 1 To ofld.Count ofld(i).Select If ofld(i).Name = "Home_Attempt_1_Date" Then If ofld(i).Result = "N/A" Then MsgBox ofld(i).Name & " is N/A, ", vbYesNoCancel Exit Sub End If End If Next i ActiveDocument.Close End Sub |
#2
|
||||
|
||||
You would probably do better to implement this via a DocumentBeforeClose macro, coded along the lines of:
Code:
Private Sub wdApp_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean) Const StrNm As String = "Home_Attempt_1_Date" If Doc.FormFields(StrNm).Result = "N/A" Then _ If MsgBox(StrNm & " is N/A." & vbCr & "Continue closing?", vbYesNo) = vbNo Then _ Cancel = True End Sub Note also how much simpler the code can be made (even if you don't use this event) Alternatively, see: http://word.mvps.org/faqs/macrosvba/...eforeClose.htm
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Close 'downloads' window with VBA | CatMan | Excel Programming | 6 | 12-14-2012 01:34 PM |
EXCEL tries to close a file | userman | Excel | 2 | 05-31-2012 03:15 AM |
Message replys are shown at the bottom of the message, how can I get them to the top | Gardy | Outlook | 3 | 05-23-2012 01:20 AM |
Prompt when close the document | ubns | Word | 15 | 04-29-2012 10:07 PM |
Is there an exit on close ? | mhdadmh | Word | 0 | 10-12-2006 04:28 PM |