PC Review


Reply
Thread Tools Rate Thread

Code to automatically close an Excel spreadsheet

 
 
JoAnn
Guest
Posts: n/a
 
      5th Sep 2008
I'm using code I found in an earlier email thread to save/close a workbook
after 1 minute, after prompting the user to see if he/she is still there
(resets the timer if Yes is clicked).

The code works fine as long as the user has exited out of a data field. But
if the user has entered data in a field but hasn't clicked out of it, the
wkbook stays open as it would if the code weren't there.

1) How can I force it to exit the field, save whatever has been entered &
close?

2) I would also like to add a countdown message to the "Are you there?"
prompt (i.e. "If you do not click Yes, this workbook will close in <#
seconds>"). How can I do that?

The code being used is below:

In Thisworkbook:

Private Sub Workbook_Open()
Application.OnTime Now() + TimeValue("00:01:00"), "CloseMe"
End Sub

In a New Module:

Public Sub CloseMe()
Dim SH As IWshRuntimeLibrary.WshShell
Dim Res As Long

Set SH = New IWshRuntimeLibrary.WshShell
Res = SH.Popup(Text:="Are you still there?", secondstowait:=3, _
Title:="Doc Tracking List Check", Type:=vbYesNo)
If Res = vbYes Then
Application.OnTime Now() + TimeValue("00:01:00"), "CloseMe"
Else
ThisWorkbook.Save
ThisWorkbook.Close
End If
End Sub

--
Thanks for your help!
JoAnn
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      5th Sep 2008
Macros do not fire while you are in edit mode. There is no way to force the
user out of edit mode. So the short answer is there is no easy way to do what
you have asked...
--
HTH...

Jim Thomlinson


"JoAnn" wrote:

> I'm using code I found in an earlier email thread to save/close a workbook
> after 1 minute, after prompting the user to see if he/she is still there
> (resets the timer if Yes is clicked).
>
> The code works fine as long as the user has exited out of a data field. But
> if the user has entered data in a field but hasn't clicked out of it, the
> wkbook stays open as it would if the code weren't there.
>
> 1) How can I force it to exit the field, save whatever has been entered &
> close?
>
> 2) I would also like to add a countdown message to the "Are you there?"
> prompt (i.e. "If you do not click Yes, this workbook will close in <#
> seconds>"). How can I do that?
>
> The code being used is below:
>
> In Thisworkbook:
>
> Private Sub Workbook_Open()
> Application.OnTime Now() + TimeValue("00:01:00"), "CloseMe"
> End Sub
>
> In a New Module:
>
> Public Sub CloseMe()
> Dim SH As IWshRuntimeLibrary.WshShell
> Dim Res As Long
>
> Set SH = New IWshRuntimeLibrary.WshShell
> Res = SH.Popup(Text:="Are you still there?", secondstowait:=3, _
> Title:="Doc Tracking List Check", Type:=vbYesNo)
> If Res = vbYes Then
> Application.OnTime Now() + TimeValue("00:01:00"), "CloseMe"
> Else
> ThisWorkbook.Save
> ThisWorkbook.Close
> End If
> End Sub
>
> --
> Thanks for your help!
> JoAnn

 
Reply With Quote
 
JoAnn
Guest
Posts: n/a
 
      8th Sep 2008
Thanks for your response.

You said there's no easy way ... is there any way at all?

I would even settle for it closing without saving just to prevent the file
from remaining open indefinitely on someone's PC. Losing a little data would
be better than tying up the worksheet & preventing other users from accessing
it.

Since the entries tie into a related action outside of Excel, we would be
able to determine that an entry is missing & rectify it after the fact. The
only thing I wouldn't want to do is quit Excel app without warning, since
they often use Excel for other things.

--
JoAnn


"Jim Thomlinson" wrote:

> Macros do not fire while you are in edit mode. There is no way to force the
> user out of edit mode. So the short answer is there is no easy way to do what
> you have asked...
> --
> HTH...
>
> Jim Thomlinson
>
>
> "JoAnn" wrote:
>
> > I'm using code I found in an earlier email thread to save/close a workbook
> > after 1 minute, after prompting the user to see if he/she is still there
> > (resets the timer if Yes is clicked).
> >
> > The code works fine as long as the user has exited out of a data field. But
> > if the user has entered data in a field but hasn't clicked out of it, the
> > wkbook stays open as it would if the code weren't there.
> >
> > 1) How can I force it to exit the field, save whatever has been entered &
> > close?
> >
> > 2) I would also like to add a countdown message to the "Are you there?"
> > prompt (i.e. "If you do not click Yes, this workbook will close in <#
> > seconds>"). How can I do that?
> >
> > The code being used is below:
> >
> > In Thisworkbook:
> >
> > Private Sub Workbook_Open()
> > Application.OnTime Now() + TimeValue("00:01:00"), "CloseMe"
> > End Sub
> >
> > In a New Module:
> >
> > Public Sub CloseMe()
> > Dim SH As IWshRuntimeLibrary.WshShell
> > Dim Res As Long
> >
> > Set SH = New IWshRuntimeLibrary.WshShell
> > Res = SH.Popup(Text:="Are you still there?", secondstowait:=3, _
> > Title:="Doc Tracking List Check", Type:=vbYesNo)
> > If Res = vbYes Then
> > Application.OnTime Now() + TimeValue("00:01:00"), "CloseMe"
> > Else
> > ThisWorkbook.Save
> > ThisWorkbook.Close
> > End If
> > End Sub
> >
> > --
> > Thanks for your help!
> > JoAnn

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Close specific Excel spreadsheet using VB Code in Access eighthman11 Microsoft Access 1 11th Dec 2008 07:29 PM
save and close automatically an excel spreadsheet PRAV Microsoft Excel Programming 1 5th Sep 2006 01:37 AM
Is there a way to insert a formula, password or macro in an excel spreadsheet that will automatically delete the spreadsheet? oil_driller Microsoft Excel Misc 1 8th Feb 2005 09:34 AM
Excel 97 does not close after spreadsheet is closed Antz Microsoft Excel Misc 1 2nd Apr 2004 07:09 PM
VBA code to automatically close file Kevin Microsoft Excel Programming 4 6th Nov 2003 04:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:13 PM.