View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
JLatham JLatham is offline
external usenet poster
 
Posts: 3,365
Default macro wich saves files

The code below should do the trick for you. Put it in the Workbook's code
segment. To get there, with Excel 2003 and earlier:
open the workbook
right-click on the Excel icon immediately to the left of the word File in
the main menu and choose [View Code] from the list that appears.
Copy the code below and paste it into the module.
Save and close the workbook.

From then on the code will begin running when you open the file. Given that
it runs without other interruption for some weird reason, it should save
itself every 10 minutes, give or take one or two seconds as long as it
remains open. The one exception would be around midnight, in which case it
could be up to 20 minutes between the last save in the previous day and the
first one for the current day.

Private Sub Workbook_Open()
Dim lastSavedClick As Long
Const delayInSeconds = 600 ' 10 minutes * 60 seconds

'get current system timer
lastSavedClick = Timer ' timer is system clock, so to speak
'set up a loop that won't end
'since 1 never equals zero
Do Until 1 = 0
'allow other things to happen, such
'such as using this workbook, or others
'or using other programs
DoEvents
If Timer (lastSavedClick + delayInSeconds) Then
'time to save the file
ThisWorkbook.Save
'reset our timer
lastSavedClick = Timer
End If
'check and see if we rolled past midnight!
If Timer < lastSavedClick Then
'yes we just blew through midnight
lastSavedClick = Timer
End If
Loop
End Sub


"orquidea" wrote:

Hi All:

I would like to set a macro which automatically saves every 10 minutes a
file which is open 24/7.

Could anyone help me with it.

Thanks in advance for your help.

Orquidea