Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 12
Default Workbook-Close StopTimer event

I'm wondering if someone can help here (running Excel 2003). I'm using VBA to
start a timer when the workbook opens. The timer calls a macro to save the
workbook every 10 minutes and restarts the timer. It works good, but the
issue I'm having is when I close the workbook, it's supposed to stop the
timer so that if Excel is left open it isn't still running the timer and
re-opening the workbook. I don't know why, but it is still opening the
workbook, even though I have a workbook-close event. And if you please, try
to not respond with a "why don't you just ____" response. I can't run any
add-ins, like AutoSave; our Excel is over a MetaFrame server and I don't have
authority, so everything must be VBA.
The VBA used is as follows:

In ThisWorkbook I have:
Private Sub Workbook_Open()
StartTimer
End Sub
Private Sub Workbook_Close()
StopTimer
End Sub

And in Module1 I have:
Public RunWhen As Double
Public Const cRunIntervalSeconds = 600
Public Const cRunWhat = "Save"

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

Sub Save()
ActiveWorkbook.Save
StartTimer
End Sub

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

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Workbook-Close StopTimer event

There is no Workbook_Close event.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopTimer
End Sub


Gord Dibben MS Excel MVP

On Wed, 9 Jan 2008 07:11:00 -0800, Stonewall Rubberbow
wrote:

I'm wondering if someone can help here (running Excel 2003). I'm using VBA to
start a timer when the workbook opens. The timer calls a macro to save the
workbook every 10 minutes and restarts the timer. It works good, but the
issue I'm having is when I close the workbook, it's supposed to stop the
timer so that if Excel is left open it isn't still running the timer and
re-opening the workbook. I don't know why, but it is still opening the
workbook, even though I have a workbook-close event. And if you please, try
to not respond with a "why don't you just ____" response. I can't run any
add-ins, like AutoSave; our Excel is over a MetaFrame server and I don't have
authority, so everything must be VBA.
The VBA used is as follows:

In ThisWorkbook I have:
Private Sub Workbook_Open()
StartTimer
End Sub
Private Sub Workbook_Close()
StopTimer
End Sub

And in Module1 I have:
Public RunWhen As Double
Public Const cRunIntervalSeconds = 600
Public Const cRunWhat = "Save"

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

Sub Save()
ActiveWorkbook.Save
StartTimer
End Sub

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


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 12
Default Workbook-Close StopTimer event

Thanks for the reply, that worked well!

"Gord Dibben" wrote:

There is no Workbook_Close event.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopTimer
End Sub


Gord Dibben MS Excel MVP

On Wed, 9 Jan 2008 07:11:00 -0800, Stonewall Rubberbow
wrote:

I'm wondering if someone can help here (running Excel 2003). I'm using VBA to
start a timer when the workbook opens. The timer calls a macro to save the
workbook every 10 minutes and restarts the timer. It works good, but the
issue I'm having is when I close the workbook, it's supposed to stop the
timer so that if Excel is left open it isn't still running the timer and
re-opening the workbook. I don't know why, but it is still opening the
workbook, even though I have a workbook-close event. And if you please, try
to not respond with a "why don't you just ____" response. I can't run any
add-ins, like AutoSave; our Excel is over a MetaFrame server and I don't have
authority, so everything must be VBA.
The VBA used is as follows:

In ThisWorkbook I have:
Private Sub Workbook_Open()
StartTimer
End Sub
Private Sub Workbook_Close()
StopTimer
End Sub

And in Module1 I have:
Public RunWhen As Double
Public Const cRunIntervalSeconds = 600
Public Const cRunWhat = "Save"

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

Sub Save()
ActiveWorkbook.Save
StartTimer
End Sub

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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
before close event with condition mohavv Excel Discussion (Misc queries) 4 November 21st 07 03:14 AM
Workbook event code won't work on laptop SoupNazi Excel Worksheet Functions 1 April 20th 07 11:38 PM
Event: open workbook Jeff Excel Discussion (Misc queries) 1 September 28th 06 02:58 PM
Event when workbook is saved or closed tk Excel Discussion (Misc queries) 2 March 16th 06 01:53 PM
workbook/sheet event macro TUNGANA KURMA RAJU Excel Discussion (Misc queries) 4 December 27th 05 12:00 PM


All times are GMT +1. The time now is 03:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"