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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Charlie G
    New Member
    • Sep 2010
    • 1

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

    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.
  • Laura Nicholaso
    New Member
    • Feb 2011
    • 2

    #2
    Hi Charlie,

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

    Copy this into any standard module:

    Code:
    Option Explicit
    
    Public RunTime
    
    
    
    Sub StartTimer()
    
    RunTime = Now + #12:10:00 AM#
    
    Application.OnTime RunTime, "SaveBook", schedule:=True
    
    End Sub
    
    
    
    
    
    Sub SaveBook()
    
    ActiveWorkbook.Save
    
    StartTimer
    
    End Sub
    
    
    
    
    
    Sub StopTimer()
    
       On Error Resume Next
    
       Application.OnTime RunTime, "SaveBook", schedule:=False
    
    End Sub
    Place this in your workbook class module:


    Code:
    Private Sub Workbook_Open()
    
    StartTimer
    
    End Sub
    
    
    
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    
    StopTimer
    
    End Sub
    This code will automatically save your workbook every 10 minutes.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Or you just set it up in the options... No need to create a macro for it when it's natively supported.

      Comment

      Working...