Autoclose document after 10mins

M

Mike P.

I would like to have a document automatically saved and
closed after being idle for 10 minutes. How would I do
that?
 
H

Helmut Weber

Hi Mike,
have a look at this:
Sub Test443()
' this is the start macro
' the interval is 15 seconds for testing purposes
ActiveDocument.Save
Application.OnTime _
When:=Now + TimeValue("00:00:15"), _
Name:="Test444"
End Sub
Sub Test444()
If ActiveDocument.Saved = True Then
' if saved = true then nothing was changed
' or almost nothing to be accurate
' as some actions like changing a docproperty
' are not regarded as document change
MsgBox "Time to go" ' for testing only
ActiveDocument.Close
Else
Test443
End If
End Sub
 
J

Jezebel

Helmut, this line of code is risky:

Now + TimeValue("00:00:15")

because it makes assumptions about the machine's regional settings.
(Reasonable assumptions, to be sure, but assumptions none the less.)

Better to use DateAdd().
 
H

Helmut Weber

Hi Jezebel
Helmut, this line of code is risky
Now + TimeValue("00:00:15"
because it makes assumptions about the machine's regional settings
(Reasonable assumptions, to be sure, but assumptions none the less.
Better to use DateAdd()
 
J

Jezebel

Yes, it would actually work in most of the regions I've dealt with too. The
point is, it's not *guaranteed* to work. There are regional settings you
*could* choose that would cause it to fail.
 

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