Message box upon exiting help

D

Debbiedo

I have the following code in my MS Word 2003 protected form to
display
a message box when saving but how can I modify it to display when
exiting (ie, hitting the X in the corner or Exit from the File menu)?

Public Sub FileSave()


Dim Answer As Integer
Dim Msg As String
On Error Resume Next
Msg = "If Student ID is NOT filled out" & _
vbCr & "click Cancel and go back."
Answer = MsgBox(Msg, vbOKCancel)
If Answer = vbOK Then
ActiveDocument.Save
End If


End Sub


Thanks in advance
 
C

Cindy M.

Hi Debbiedo,
I have the following code in my MS Word 2003 protected form to
display
a message box when saving but how can I modify it to display when
exiting (ie, hitting the X in the corner or Exit from the File menu)?

Public Sub FileSave()


Dim Answer As Integer
Dim Msg As String
On Error Resume Next
Msg = "If Student ID is NOT filled out" & _
vbCr & "click Cancel and go back."
Answer = MsgBox(Msg, vbOKCancel)
If Answer = vbOK Then
ActiveDocument.Save
End If


End Sub
You'd also need to have a macro named FileClose.

But if what you really want is to trap every time the document saves,
it would probably be better to use the DocumentBeforeSave event. This
is a bit more complicated than using macros to repurpose built-in
commands. You'll want to read up on using Application events in the VBA
Help.

And if you need more assistance, I recommend following up on this in a
word.vba newsgroup, as this newsgroup is more for end-user questions.
You'll find many more people to answer macro questions in one of the
word.vba newsgroups.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top