By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,708 Members | 2,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,708 IT Pros & Developers. It's quick & easy.

Looking for an excel macro (or VBA code) to have workbook auto save every hour.

P: 1
I have a an extensive spreadsheet that is used for timing customers for billing time used. An occasional power problem has lost all data for that day. Used be multiple people, no one does an occasional Save manually.
Sep 17 '10 #1
Share this Question
Share on Google+
2 Replies


P: 2
Hi Charlie,

Interesting question. I found this on the MrExcel.com forum:

Copy this into any standard module:

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Public RunTime
  4.  
  5.  
  6.  
  7. Sub StartTimer()
  8.  
  9. RunTime = Now + #12:10:00 AM#
  10.  
  11. Application.OnTime RunTime, "SaveBook", schedule:=True
  12.  
  13. End Sub
  14.  
  15.  
  16.  
  17.  
  18.  
  19. Sub SaveBook()
  20.  
  21. ActiveWorkbook.Save
  22.  
  23. StartTimer
  24.  
  25. End Sub
  26.  
  27.  
  28.  
  29.  
  30.  
  31. Sub StopTimer()
  32.  
  33.    On Error Resume Next
  34.  
  35.    Application.OnTime RunTime, "SaveBook", schedule:=False
  36.  
  37. End Sub
  38.  
  39.  
  40.  
  41.  
  42.  
Place this in your workbook class module:


Expand|Select|Wrap|Line Numbers
  1. Private Sub Workbook_Open()
  2.  
  3. StartTimer
  4.  
  5. End Sub
  6.  
  7.  
  8.  
  9. Private Sub Workbook_BeforeClose(Cancel As Boolean)
  10.  
  11. StopTimer
  12.  
  13. End Sub
  14.  
  15.  
  16.  
This code will automatically save your workbook every 10 minutes.
Feb 22 '11 #2

Rabbit
Expert Mod 10K+
P: 12,369
Or you just set it up in the options... No need to create a macro for it when it's natively supported.
Feb 22 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.