Excel/Auto Save As

Advertisement


Question
Dear Tom,

My question has to do with VBA coding in Excel 2007. I'm writing a macro that saves to a new workbook every 60 minutes. The purpose of this is to stop relying on a user to keep saving and to have a stop gap measure in place incase the user manages to mess up any of the other formulas.

My problem is going from one day to the next, the auto save as feature errors out. Excel asks me to overwrite an existing document.

Here is my code in its current form:

Public dTime As Date

Sub MySaveAs()
   Application.EnableEvents = False
   dTime = Time + TimeValue("01:00:01")
   Application.OnTime dTime, "MySaveAs"
   ThisWorkbook.SaveAs Filename:="LPDC Leak Test QC " & Format(Now, "mm-dd-yyyy hhmmss"), ConflictResolution:=xlLocalSessionChanges
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
   Application.OnTime dTime, "MySaveAs", , False
End Sub

Private Sub Workbook_Open()
   dTime = Time + TimeValue("01:00:01")
   Application.OnTime dTime, "MySaveAs"
End Sub


Thank you for taking the time to read my question and I appreciate any advice or solution that you may have.

Answer
Brian,

Your filename appears be unique enough to prevent a duplicate.  Given that I can only guess that you procedure is getting called twice at some point - perhaps some interaction with the workbook open event.

I would say just instruct the code to ignore the warning


Sub MySaveAs()
  Application.EnableEvents = False
  dTime = Time + TimeValue("01:00:01")
  Application.OnTime dTime, "MySaveAs"
  Application.DisplayAlerts = False
  ThisWorkbook.SaveAs Filename:="LPDC Leak Test QC " & Format(Now, "mm-dd-yyyy hhmmss"), ConflictResolution:=xlLocalSessionChanges
  Application.DisplayAlerts = True
End Sub

--
Regards,
Tom Ogilvy

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2016 About.com. All rights reserved.