Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Close & save a file at set time only IF the file is open


I'm trying to have a file auto-Close (with a Save) at a set time ever
day IF it's open at that time.
To do this, I've put the following code in 'ThisWorkbook':

Private Sub Workbook_Open()
Application.OnTime TimeValue("17:15:00"), "TimeMacro"
End Sub

And I've put this in Module 1:

Sub TimeMacro()
Application.DisplayAlerts = False
ActiveWorkbook.Close
End Sub

That works fine in that if the file is open, the file is automaticall
saved and closed. However if the file is NOT open at the set tim
(17:15) and Excel is running, Excel tries to re-open the file (gives m
the Enable macro message) to run the macro, and I want to avoid this.
understand why the macro is doing what it's doing, but how can I ge
Excel to not run TimeMacro when the file is closed.
Many thanks,
Cliv

--
Clivey_U
-----------------------------------------------------------------------
Clivey_UK's Profile: http://www.excelforum.com/member.php...fo&userid=3256
View this thread: http://www.excelforum.com/showthread.php?threadid=53778

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Close & save a file at set time only IF the file is open

You would need to cancel the scheduled event in the BeforeClose event.
However, the user could possibly cancel when prompted to save and the
workbook is never closed.

If this is for you own use, you could put the macro in the personal.xls and
run it from there. Then have the macro check for the workbook being open

http://www.cpearson.com/excel/ontime.htm

for example of cancelling an ontime event.

http://www.cpearson.com/excel/events.htm for an overview of events.

--
Regards,
Tom Ogilvy


"Clivey_UK" wrote:


I'm trying to have a file auto-Close (with a Save) at a set time every
day IF it's open at that time.
To do this, I've put the following code in 'ThisWorkbook':

Private Sub Workbook_Open()
Application.OnTime TimeValue("17:15:00"), "TimeMacro"
End Sub

And I've put this in Module 1:

Sub TimeMacro()
Application.DisplayAlerts = False
ActiveWorkbook.Close
End Sub

That works fine in that if the file is open, the file is automatically
saved and closed. However if the file is NOT open at the set time
(17:15) and Excel is running, Excel tries to re-open the file (gives me
the Enable macro message) to run the macro, and I want to avoid this. I
understand why the macro is doing what it's doing, but how can I get
Excel to not run TimeMacro when the file is closed.
Many thanks,
Clive


--
Clivey_UK
------------------------------------------------------------------------
Clivey_UK's Profile: http://www.excelforum.com/member.php...o&userid=32569
View this thread: http://www.excelforum.com/showthread...hreadid=537788


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Close & save a file at set time only IF the file is open


Tom,
Many thanks for that. Looks like just what I need. I should have
thought of using BeforeClose.
Clive

Tom Ogilvy Wrote:
You would need to cancel the scheduled event in the BeforeClose event.
However, the user could possibly cancel when prompted to save and the
workbook is never closed.



--
Clivey_UK
------------------------------------------------------------------------
Clivey_UK's Profile: http://www.excelforum.com/member.php...o&userid=32569
View this thread: http://www.excelforum.com/showthread...hreadid=537788

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open, Save and close Excel 2007 file with a cmd command Hugo Pinto Excel Discussion (Misc queries) 5 March 3rd 08 10:05 PM
Each time I close an Excel file, it asks if I want to save. Doug Bell Excel Discussion (Misc queries) 4 July 24th 07 07:44 PM
Auto Open file VBA Refresh MS Query Save Close gcutter[_2_] Excel Programming 2 September 26th 05 03:07 PM
Open excel file, enter values, save & close JCanyoneer Excel Programming 5 April 4th 05 04:40 PM
Automate open file, update links, run macro, close and save file Geoff[_7_] Excel Programming 2 August 26th 03 10:13 PM


All times are GMT +1. The time now is 12:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"