Using AUTOEXIT

S

Steve Wylie

We're having some problems with our network at the moment. One of the
new "features" is that sometimes, when you close a document in Word,
Word also exits completely as well. I wanted to put an AutoExit macro
on everyone's machines to ask "You are about to quit Word - is this
okay?" [Yes/No] whenever Word tries to exit. If they click Yes, Word
will continue to exit; if they click No, Word will not exit and will
just sit there with a blank "gray" screen.

If Word macros were programmed in Javascript I could do something like
ONEXIT="Return MsgBox()" and I could have Msgbox return FALSE (which
would cancel the exit procedure) or TRUE (which would exit as normal).

How do I do the same thing in VBA? Is there a way to get the macro to
cancel the exit procedure in its tracks?

Steve Wylie
 
S

Steve Wylie

No, that's not it I'm afraid. This affect closing the document - I want a
macro that will halt the Exiting of the application completely. So far I
have come up with:

Sub AutoExit()

response = MsgBox("Do you want to quit Word?", vbYesNo)
If response = vbYes Then Application.Quit

End Sub

However, I need something just before the End Sub to halt the exiting of
Word. At the moment it quits anyway.

Steve Wylie
 
S

Steve Wylie

I have also tried replacing the FileExit command with my own macro command:

Sub FileExit()

response = MsgBox("Do you want to quit Word?", vbYesNo)
If response = vbYes Then WordBasic.FileExit

End Sub

.... but this only works with the user goes File/Exit on the menus. It
doesn't even work when they manually close Word by clicking on the X in the
top right hand corner of the window, much less when my network fault forces
Word to close.

Steve
 
J

Jay Freedman

Hi Steve,

I see your point. Neither AutoExit nor the application event handler
oApp_Quit (see http://word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm)
offers a Cancel parameter to stop the shutdown.

However, a userform's QueryClose event handler does have such a
parameter, so some clever folks have figured out that they can run a
dummy userform which, if it refuses to close, prevents the whole app
from shutting down. Here's a discussion of the technique in Access,
but something similar should work in Word:
http://dbforums.com/t362717.html
 
S

Steve Wylie

Hmm. The Access solution is a bit too advanced for me, but it's given me an
idea about "forcing" Word to notify a user on shutdown.

If Normal.dot is changed (or thinks it's been changed) during a session,
there is a Word option to prompt about saving Normal.dot when Word closes.

What I need is a "transparent" way of changing/unchanging Normal.dot when
Word starts up, so a user can be told if they get the message and did not
intend to close Word down, they could just click Cancel and Word will not
shut down.

But how could I arrange for this to happen so the user would not have to do
anything themselves on startup? I don't really want them going into the VBA
editor and manually changing some macro text or other to force the
Normal.dot to change...

Steve Wylie
 
J

Jonathan West

Steve Wylie said:
Hmm. The Access solution is a bit too advanced for me, but it's given me
an
idea about "forcing" Word to notify a user on shutdown.

If Normal.dot is changed (or thinks it's been changed) during a session,
there is a Word option to prompt about saving Normal.dot when Word closes.

What I need is a "transparent" way of changing/unchanging Normal.dot when
Word starts up, so a user can be told if they get the message and did not
intend to close Word down, they could just click Cancel and Word will not
shut down.

But how could I arrange for this to happen so the user would not have to
do
anything themselves on startup? I don't really want them going into the
VBA
editor and manually changing some macro text or other to force the
Normal.dot to change...

You don't need to change normal.dot, you just need to kid Word into
believing it has been changed. This will do the trick

NormalTemplate.Saved = False

To make Word think that normal.dot hasn't been changed, do this

NormalTemplate.Saved = True
 
S

Steve Wylie

Well, that will certainly work - thanks. I'll stick that in an AUTOEXEC
macro.

Steve
 

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