Hi All :)
What is the best way to put an automatic closing timer on a userForm? In
this case, the userform is in the docment rather than in an attached
template.
sub autopen()
Application.OnTime When:=Now + TimeValue("00:00:30"), _
Name:="TestClose"
userForm333.Show
End Sub
' The above starts a 30 second timer upon opening a file, then shows
userForm333, then after 30 seconds tries to run the "TestClose" code below
Sub testClose()
ActiveDocument.Save
ActiveDocument.Close
End Sub
Word2003, Windows XP
But, while the userForm is open, the close document will not run. How best
to remedy?
TIA
Gil
Gil Carter, MD, JD, FP, medical programming
http://www.TenSecondMedicalRecord.com, in use since 1990, free since 1997
http://www.KeyChainEMR.com Walk up to the medical ward computer, plug in,
do what you need, unplug and walk away.
Jay Freedman - 30 Apr 2006 18:59 GMT
Do you really want to close the document after 30 seconds, or do you
just want the userform to close then?
If it's just the userform, see
http://word.mvps.org/FAQs/Userforms/CreateASplashScreen.htm.
If it's the whole document, then set up the userform as in the
article, and change the AutoOpen macro to something like this:
Sub AutoOpen()
userForm333.Show
ActiveDocument.Close
End
and discard the testClose macro. The AutoOpen macro suspends on the
.Show call until the userform closes, and then the .Close statement
runs.
I wouldn't bother saving the document unless the userform contains
some code in the Userform_Initialize or Userform_Activate procedure
that could change the document's contents -- there's no chance for
anything else to have an effect that needs saving.
Another word of advice: don't bother putting any code after the .Close
statement. Because the macro is in the document instead of a template,
the .Close statement unloads the code from memory, so nothing after
that can get a chance to run.
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
>Hi All :)
>What is the best way to put an automatic closing timer on a userForm? In
[quoted text clipped - 28 lines]
>http://www.KeyChainEMR.com Walk up to the medical ward computer, plug in,
>do what you need, unplug and walk away.
Helmut Weber - 30 Apr 2006 19:34 GMT
Hi Jay,
though with vbmodeless closing seems to work,
it indeed makes no sense to close the doc
invariably of what else is going on.

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
Helmut Weber - 30 Apr 2006 19:18 GMT
Hi,
try showing the userform modeless, like:
Sub autoopen()
Application.OnTime When:=Now + _
TimeValue("00:00:03"), _
Name:="TestClose"
Load UserForm1 '?
UserForm1.Show vbModeless
End Sub
Sub testClose()
UserForm1.Hide '?
Unload UserForm1
ActiveDocument.Save
ActiveDocument.Close
End Sub
Lines commented by '? seem to be redundant.

Signature
Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
gils usenet acct - 30 Apr 2006 23:29 GMT
Hi guys,
I'll give it a try
The reason for closing the file in 30 seconds is to allow 6 schedulers on an
intranet to find out which worker is up next in a lineup, but not let them
leave the file open. If the file is open, other schedulers would not be
able to use it. Actually, I'll probably make it 60 seconds, but that'll be
more than enough time for the scheduler to see which worker is next, and
click a button that tics off the name of the worker selected .
:)
Thanks for the idea. A first pass at it seems to work fine. :)
:)
Happy Camper,
Gil
> Hi,
>
[quoted text clipped - 16 lines]
>
> Lines commented by '? seem to be redundant.