PDA

View Full Version : Close Document if no activity



RBorg
03-08-2005, 03:38 PM
Hi There,:hi:
I'm new to this forum. I have a Word document that resides on our shared drive. The Word document is mail merged with an Excel workbook. The problem is user will open the mail merge document and minimize or they leave their computer and evryone else will be locked out (or read only) from the document and/or the log sheet. I need to have a code that will automatically shut down the Word document if there is no activity after 30 minutes.

Any suggestions?

fumei
03-09-2005, 02:15 PM
That would be non-trivial. You would need to define "activity".

What if they just move the mouse around the screen? Is that "activity"?

What if they move their mouse around, looking at menus? Is that "activity"

What if they typed something...then deleted everything they typed? Is that activity?

What if they typed a whole bunch of stuff....but did not save it for 30 minutes? Is THAT activity?

If you are asking for a time function marking when the file is opened and when it is SAVED - that would be simpler. Detecting if the file has been saved in the last 30 minutes could be done. But "activity"....that would have to be PRECISELY defined, because otherwise you are asking for some sort of code that is doing constant checking. Constant checking sucks up resources and is generally a bad programming practice. Unless of course you are a screen saver.....

TonyJollans
03-09-2005, 05:13 PM
This can almost be done in Word (it is easier in Excel!), but the trouble is that if you do so, the code won't run when Word does not have the Windows focus. So if someone opens the document and then switches to another app nothing will happen (in Word) until they switch back to Word - at that point they might find themselves thrown out which would point out to them that they had been naughty but wouldn't have helped free up the document for other users.

To do it in Word you need to use Application.OnTime and Application Events (DocumentChange and WindowSelectionChange). BUT, you cannot detect simple typing (mouse clicks and cursor movement you get, but not typing) so just in case all they have done for 30 minutes is straightforward typing you need to make some sort of extra check against document content. As I suspect it won't work for you I won't go into any more detail. I don't know off the top of my head whether APIs could do it for you - it should be possible.

Anne Troy
03-09-2005, 05:37 PM
Wouldn't it be easier to use our code that runs the mail merge and closes the doc right away?

http://www.vbaexpress.com/kb/getarticle.php?kb_id=122

Or perhaps you can find something similar...

mdmackillop
03-09-2005, 05:57 PM
Hi DB
I read this question and never thought of my KB item:blush. I'm glad someone is paying attention!

RBorg
03-09-2005, 05:59 PM
Thank you all for your responses.
Tony,
I appreciate your detailed explaination and yes it is easier to do this in Excel. In fact I already have code to do this in Excel that I picked up from the Mr.Excel forum and iit works perfect!!!

Dreamboat,
Thanks for the link to that code. It looks like something that I can definitely use. I will give this a try tomorrow.



Thanks again everyone.

This forum is awsome!!!