How can I automatically determine a document idle time & close it

M

ML

I need to write some vba code to determine a specific document's idle time
and if its more than 3 minutes it needs to save and close the document
without affecting other documents I might be working on.
 
H

Helmut Weber

Something along these lines:

' normal.dot
' -------------------------------------------------
Option Explicit
Dim ThisDoc As Document
' -------------------------------------------------
Sub autoopen()
Set ThisDoc = ActiveDocument
If ThisDoc.Name = "DocToWatch.doc" Then
StartIdle
End If
End Sub
' -------------------------------------------------
Sub StartIdle()
Application.OnTime _
When:=Now + TimeValue("00:00:05"), _
Name:="EndIdle"
End Sub
' -------------------------------------------------
Sub EndIdle()
MsgBox ThisDoc.Name & " = idle" 'for testing
With ThisDoc
If .Saved = True Then
.Close
Else
.Save
StartIdle
End If
End With
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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