View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.misc
Dominic Dominic is offline
external usenet poster
 
Posts: 26
Default Can I set a file to auto-open and save at each month begin dat

Appreciate the help!

"Gord Dibben" wrote:

See Chip Pearson's site for OnTime method.

http://www.cpearson.com/excel/OnTime.aspx

Here is an example using Chip's procedures.

In a General Module..........................

Public RunWhen As Double
Public Const cRunIntervalSeconds = 120 ' two minutes
Public Const cRunWhat = "TheSub"


Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime EarliestTime:=RunWhen, Procedu=cRunWhat, _
Schedule:=True
End Sub

Sub Example_Macro()
ActiveSheet.Range("A1:F10").Interior.ColorIndex = 3
End Sub

Sub TheSub()
ThisWorkbook.Save
StopTimer
Application.Quit
End Sub

Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=RunWhen, Procedu=cRunWhat, _
Schedule:=False
End Sub

In Thisworkbook Module..............................

Private Sub Workbook_Open()
Example_Macro 'runs the macro
StartTimer 'starts the timer to save workbook and shut down Excel
End Sub

I''ll leave it to you to figure out a way to prevent macro warning when
workbook opens.


Gord

On Fri, 7 Aug 2009 18:06:01 -0700, Dominic
wrote:

Thanks for the solution! Got the task scheduler to open the file, but how to
I employ the workbook event code to close and save?

"Gord Dibben" wrote:

Windows Task Scheduler can start Excel with a designated workbook.

The workbook event code makes the change and saves the workbook and closes
Excel.


Gord Dibben MS Excel MVP

On Fri, 7 Aug 2009 09:36:01 -0700, JLatham
wrote:

If what I understand is correct, you cannot do it.

What I understand now is that you want an Excel file to open itself at
midnight and then save itself so that its date stamp will reflect the next
day.

A closed file cannot open itself. You would need another
application/scheduler running somewhere to perform that task. And right off
the top of my head I don't know of any - they probably exist, I've just never
had a call to use one.

"Dominic" wrote:

Well, let's just use TODAY() as an example. I save the file now, but want to
auto-open and save the file at midnight so the date on the file shows the
change in the date.

The need for this is that the file is used as an external data provider for
reporting. If the file is not saved with the change, the previous saved data
will be fed into reports instead of today's data. Thanks

"JLatham" wrote:

Probably, but a couple of examples of your date-dependent formulas would sure
help.

Also, look at the NOW() function in Excel. That may help you with this
problem. You can do math with it that will give elapsed time between dates,
as NOW()-30 for a date 30 days previous to the current date.


"Dominic" wrote:

Want the excel file to open so the date-dependent formulas refresh to the new
month. Then save the file. Can this be done?