Close Open Workbook

  • Thread starter Thread starter Lucy
  • Start date Start date
L

Lucy

This is my third posting of the same question in the past
couple weeks with no solution in sight. I am getting
little cranky with all the help for everything else, but
what I need. Here is the problem:

I need to be able to close any open Excel file before I
start an upload. These files are located on a mainframe
and people all over the place leave the apps open when
they go home, thus preventing me from doing my upload. I
do know the code how the close the workbooks, so please
do not offer it.

All I need is the code to trigger it. Therefore if the
file stays open past specific time (e.g. 1 AM) this event
will come into play and close the app (similar to On
Timer event in Access).

In laymen terms: If the time is 1:00 AM and the workbook
is still open, QUIT IT (all without any user
interaction). Like a timer on your TV.

Does anybody (including the Excel MVP's) know a code how
to trigger this when all the users left the office with
the workbooks open?

Thank you.

Lucy
 
Well, YOUR workbook must be open. In its open event:

Application.OnTime timevalue("01:00:00 AM"),"MyMacro"

Then, in a regular module, have your MyMacro close all open workbooks.
 
Thank you for your suggestion. I was already using the
Application.OnTime, but in the wrong event. I have
changed it to the following and it worked like magic:

Public Sub Auto_Open()
Application.OnTime TimeValue
("01:00:00"), "Quit_Workbook"
End Sub

Sub Quit_Workbook()
With Application
.DisplayAlerts = False
.Quit
End With
End Sub

Thank you.

Lucy
 
Thank you for the source of info, but I have used
different idea suggested by Bob Umlas:

Public Sub Auto_Open()
Application.OnTime TimeValue
("01:00:00"), "Quit_Workbook"
End Sub

Sub Quit_Workbook()
With Application
.DisplayAlerts = False
.Quit
End With
End Sub

This works great but I will also explore the source you
suggested.

Thank you.

Lucy
 
Back
Top