473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.
Sep 17 '10 #1
2 7006
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
12,516 Expert Mod 8TB
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

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

Similar topics

2
by: Mrs Howl | last post by:
I don't know if there's even a way to do what I want. I click on a button in an Access form, and it opens an instance of Excel, and opens a workbook and runs a macro that's in it. So far, fine,...
6
by: geronimo_me | last post by:
Hi, I am trying to run an Excel macro from an Access module, however when I run the code the macro runs but then I get an error in Access. The error is: Run-time error "440", Automation error. ...
1
by: Michelle | last post by:
Hi All, I have an ASP.NET application with a session timeout of 20 minutes - for security reasons. I have a web form in this application that I need to Auto Save every 15 minutes (in case the...
0
by: modularmix | last post by:
Does anyone know how to run the Excel Macro for two different spreadsheets in parallel. Here is the code that works sequentially. Workbooks.Open Filename:="C:\Documents and...
0
by: kittu513 | last post by:
Hi I need some help regarding the alignment of the value in the active cell. my code is like this (its VB code to implement an Excel macro) Range("B1").Select ActiveCell.Offset(50,...
0
by: blackjackkiller | last post by:
Hi Need help in automating the report.Let me give the explanation what i need that might help u in understanding it. 1 need excel macro to run a query to pull data from sql server for specific...
7
by: NeverLift | last post by:
This is probably answered elsewhere, but I've searched the Web and VBA for Excel manual, find no answers. I have a VBA-coded macro in an Excel workbook that is to open another existing workbook --...
1
by: Catbkr1 | last post by:
I have to automatically create some Excel Spreadsheets based on automatically generated .CSV files that are produced overnight. Each .CSV has several columns that need to be deleted. The same...
1
MitchR
by: MitchR | last post by:
Good Morning Folks; I have a question that is pretty far fetched but here goes nothing... I am looking to find a way to insert a macro into an Excel command button located in an Access VBA...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.