Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2007

Tip: Looking for answers? Try searching our database.

Automatically close document.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Richhall - 30 Mar 2007 13:05 GMT
Hi, we have a control document which a number of users update on
Fridays.  The problem is sometimes people stay in the document
preventing other people updating it.  Is there a way I could create a
script, that once a person opens a document they have 15 minutes
within the document or it will automatically close and save, allowing
someone else to then use the document.  In doing this, I would also
want a message box that says a message when the document is open, and
then with 1 minute to go also can display a message.

Cheers

Rich
Greg Maxey - 30 Mar 2007 13:29 GMT
Rich,

Just a stab.  I didn't check to see what happens if the user is away
and doesnt' acknowledge the message box:

Sub Auto_Open()
Application.OnTime When:=Now + TimeValue("00:14:00"), Name:="MsgText"
End Sub
Sub MsgText()
MsgBox "This document will save and close in 60 seconds."
Application.OnTime When:=Now + TimeValue("00:01:00"),
Name:="myFileSave"
End Sub
Sub myFileSave()
ActiveDocument.Close wdSaveChanges
End Sub

> Hi, we have a control document which a number of users update on
> Fridays.  The problem is sometimes people stay in the document
[quoted text clipped - 8 lines]
>
> Rich
Greg Maxey - 30 Mar 2007 13:35 GMT
Rich,

That won't work.  The code stops when the message box is diplayed and
doesn't continue until the user clicks OK.  Also the Sub Auto_Open
should be Sub AutoOpen

I toy around and see if I can come up with something that works.

> Rich,
>
[quoted text clipped - 27 lines]
>
> - Show quoted text -
Richhall - 30 Mar 2007 13:39 GMT
> Rich,
>
[quoted text clipped - 37 lines]
>
> - Show quoted text -

Cheers everyone!  Even a message box without an OK, is fine. Just a
notice really.
Greg Maxey - 30 Mar 2007 13:49 GMT
Ok, you can use a UserForm timed to close as the warning message.

Put this code in the document project module:

Sub AutoOpen()
Application.OnTime When:=Now + TimeValue("00:14:00"), Name:="MsgText"
End Sub
Sub MsgText()
UserForm1.Show
Application.OnTime When:=Now + TimeValue("00:01:00"),
Name:="myFileSave"
End Sub
Sub myFileSave()
ActiveDocument.Close wdSaveChanges
End Sub

Add a userform with a caption and label to suit your needs and add
this code to the Userform:

Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)
Private Sub UserForm_Activate()
DoEvents
'Set the display time in milliseconds
Sleep 1000
Unload Me
End Sub

> > Rich,
>
[quoted text clipped - 42 lines]
>
> - Show quoted text -
Richhall - 30 Mar 2007 14:29 GMT
Thanks,  Sorry not a VB expert or anything.  So I go to
Tools>Macros>VB Editor and under projects put the first bit in the
This Document panel and save,  What do I need to do with the second
bit please?
Greg Maxey - 30 Mar 2007 15:07 GMT
Rich,

You will need to open the VB Editor (Alt+F11).  If not already
displayed, display the Project Explorer and Properties windows using
the View menu.

Click on the Project(your document name) tree then use the Insert menu
to insert a module

Paste the first bit of code in the module

Use the Insert menu to insert a Userform.

Use the toolbox to place a lable on the userform and then use the
properties window to give the userform and the label a "Caption"

Right click the Userform and select view code.  Paste the second bit
of code in.

> Thanks,  Sorry not a VB expert or anything.  So I go to
> Tools>Macros>VB Editor and under projects put the first bit in the
> This Document panel and save,  What do I need to do with the second
> bit please?
Richhall - 30 Mar 2007 15:41 GMT
> Rich,
>
[quoted text clipped - 21 lines]
>
> - Show quoted text -

Cheers Greg

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.