Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Stop vbTimer

Hello Everybody,

I have copied a code for a timer in a post and applied it to my workbook to
automatically show a userform after a short period of time.
My big problem is that when I close the workbook without quitting Excel the
timer continue running and re-open my workbook after the preset period to
show the userform again.
Is there a way to have the timer stopped when closing the workbook?

My code bellow:

In Module:

Option Explicit

Public nSaveWB As Date

Public Sub SetSaveWBTimer()
nSaveWB = Now + TimeSerial(0, 0, 5) ' 5 minutes
Application.OnTime nSaveWB, "SaveWB"
End Sub

Public Sub SaveWB()
Alerte.Show
End Sub


In ThisWorkbook:

Private Sub workbook_open()
Alerte.Show
End Sub


In Userform: (called Alerte)

Private Sub CommandButton1_Click()
Alerte.Hide
Call SetSaveWBTimer
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Call SetSaveWBTimer
End If
End Sub


Thanks for your help.
--

Regards, Cajeto 63.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Stop vbTimer

Hi Cajeto63,
I use the below code to show the time on my userform. In the terminate event
of the userform I call Stoptimer so that I don't get the same problem... (you
might put it in the workbook beforeclose event)

Hope it helps,
Ozgur


Public RunWhen As Double
Public Const cRunIntervalSeconds = 60
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=True
End Sub


Sub The_Sub()
UserForm2.Label475.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label476.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label514.Caption = Format(Now, "dd mmm yy hh:mm")
Call StartTimer
End Sub


Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,
schedule:=False
End Sub


"Cajeto 63" wrote:

Hello Everybody,

I have copied a code for a timer in a post and applied it to my workbook to
automatically show a userform after a short period of time.
My big problem is that when I close the workbook without quitting Excel the
timer continue running and re-open my workbook after the preset period to
show the userform again.
Is there a way to have the timer stopped when closing the workbook?

My code bellow:

In Module:

Option Explicit

Public nSaveWB As Date

Public Sub SetSaveWBTimer()
nSaveWB = Now + TimeSerial(0, 0, 5) ' 5 minutes
Application.OnTime nSaveWB, "SaveWB"
End Sub

Public Sub SaveWB()
Alerte.Show
End Sub


In ThisWorkbook:

Private Sub workbook_open()
Alerte.Show
End Sub


In Userform: (called Alerte)

Private Sub CommandButton1_Click()
Alerte.Hide
Call SetSaveWBTimer
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Call SetSaveWBTimer
End If
End Sub


Thanks for your help.
--

Regards, Cajeto 63.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Stop vbTimer

Hi Ozgur,
Thank you very much for you help.

I replaced the code I was using with yours and it partially works but I get
another problem.
When I run the sub StopTimer by hand from the VB windows it stops showing
the userform which is a very good point.

But VB does not want me to use the Workbook_BeforeClose event. It gives me a
compile error saying:"Procedure declaration does not match description of
event or procedure having the same name" and I'm not sure I understand what
it means.
Could it come from the fact that I already have a Workbook_open event in the
workbook?

And if so how can I get rid of the problem?

--


Regards, Cajeto 63.





"Ozgur Pars" wrote:

Hi Cajeto63,
I use the below code to show the time on my userform. In the terminate event
of the userform I call Stoptimer so that I don't get the same problem... (you
might put it in the workbook beforeclose event)

Hope it helps,
Ozgur


Public RunWhen As Double
Public Const cRunIntervalSeconds = 60
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=True
End Sub


Sub The_Sub()
UserForm2.Label475.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label476.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label514.Caption = Format(Now, "dd mmm yy hh:mm")
Call StartTimer
End Sub


Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,
schedule:=False
End Sub


"Cajeto 63" wrote:

Hello Everybody,

I have copied a code for a timer in a post and applied it to my workbook to
automatically show a userform after a short period of time.
My big problem is that when I close the workbook without quitting Excel the
timer continue running and re-open my workbook after the preset period to
show the userform again.
Is there a way to have the timer stopped when closing the workbook?

My code bellow:

In Module:

Option Explicit

Public nSaveWB As Date

Public Sub SetSaveWBTimer()
nSaveWB = Now + TimeSerial(0, 0, 5) ' 5 minutes
Application.OnTime nSaveWB, "SaveWB"
End Sub

Public Sub SaveWB()
Alerte.Show
End Sub


In ThisWorkbook:

Private Sub workbook_open()
Alerte.Show
End Sub


In Userform: (called Alerte)

Private Sub CommandButton1_Click()
Alerte.Hide
Call SetSaveWBTimer
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Call SetSaveWBTimer
End If
End Sub


Thanks for your help.
--

Regards, Cajeto 63.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Stop vbTimer

Cajeto,
I tried it out now and I have no problems with the before_close event.
Maybe you can post your code.

Just to set the record straight this is not my code(I wish) I found it on
the net...

Ozgur

"Cajeto 63" wrote:

Hi Ozgur,
Thank you very much for you help.

I replaced the code I was using with yours and it partially works but I get
another problem.
When I run the sub StopTimer by hand from the VB windows it stops showing
the userform which is a very good point.

But VB does not want me to use the Workbook_BeforeClose event. It gives me a
compile error saying:"Procedure declaration does not match description of
event or procedure having the same name" and I'm not sure I understand what
it means.
Could it come from the fact that I already have a Workbook_open event in the
workbook?

And if so how can I get rid of the problem?

--


Regards, Cajeto 63.





"Ozgur Pars" wrote:

Hi Cajeto63,
I use the below code to show the time on my userform. In the terminate event
of the userform I call Stoptimer so that I don't get the same problem... (you
might put it in the workbook beforeclose event)

Hope it helps,
Ozgur


Public RunWhen As Double
Public Const cRunIntervalSeconds = 60
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=True
End Sub


Sub The_Sub()
UserForm2.Label475.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label476.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label514.Caption = Format(Now, "dd mmm yy hh:mm")
Call StartTimer
End Sub


Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,
schedule:=False
End Sub


"Cajeto 63" wrote:

Hello Everybody,

I have copied a code for a timer in a post and applied it to my workbook to
automatically show a userform after a short period of time.
My big problem is that when I close the workbook without quitting Excel the
timer continue running and re-open my workbook after the preset period to
show the userform again.
Is there a way to have the timer stopped when closing the workbook?

My code bellow:

In Module:

Option Explicit

Public nSaveWB As Date

Public Sub SetSaveWBTimer()
nSaveWB = Now + TimeSerial(0, 0, 5) ' 5 minutes
Application.OnTime nSaveWB, "SaveWB"
End Sub

Public Sub SaveWB()
Alerte.Show
End Sub


In ThisWorkbook:

Private Sub workbook_open()
Alerte.Show
End Sub


In Userform: (called Alerte)

Private Sub CommandButton1_Click()
Alerte.Hide
Call SetSaveWBTimer
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Call SetSaveWBTimer
End If
End Sub


Thanks for your help.
--

Regards, Cajeto 63.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Stop vbTimer

Ozgur,
I pasted the code I have in ThisWorkbook bellow. Thanks again for your help.

Private Sub Workbook_Open()
Alerte.Show
End Sub

Private Sub workbook_BeforeClose()
Call StopTimer
End Sub
--


Regards, Cajeto 63.





"Ozgur Pars" wrote:

Cajeto,
I tried it out now and I have no problems with the before_close event.
Maybe you can post your code.

Just to set the record straight this is not my code(I wish) I found it on
the net...

Ozgur

"Cajeto 63" wrote:

Hi Ozgur,
Thank you very much for you help.

I replaced the code I was using with yours and it partially works but I get
another problem.
When I run the sub StopTimer by hand from the VB windows it stops showing
the userform which is a very good point.

But VB does not want me to use the Workbook_BeforeClose event. It gives me a
compile error saying:"Procedure declaration does not match description of
event or procedure having the same name" and I'm not sure I understand what
it means.
Could it come from the fact that I already have a Workbook_open event in the
workbook?

And if so how can I get rid of the problem?

--


Regards, Cajeto 63.





"Ozgur Pars" wrote:

Hi Cajeto63,
I use the below code to show the time on my userform. In the terminate event
of the userform I call Stoptimer so that I don't get the same problem... (you
might put it in the workbook beforeclose event)

Hope it helps,
Ozgur


Public RunWhen As Double
Public Const cRunIntervalSeconds = 60
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=True
End Sub


Sub The_Sub()
UserForm2.Label475.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label476.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label514.Caption = Format(Now, "dd mmm yy hh:mm")
Call StartTimer
End Sub


Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,
schedule:=False
End Sub


"Cajeto 63" wrote:

Hello Everybody,

I have copied a code for a timer in a post and applied it to my workbook to
automatically show a userform after a short period of time.
My big problem is that when I close the workbook without quitting Excel the
timer continue running and re-open my workbook after the preset period to
show the userform again.
Is there a way to have the timer stopped when closing the workbook?

My code bellow:

In Module:

Option Explicit

Public nSaveWB As Date

Public Sub SetSaveWBTimer()
nSaveWB = Now + TimeSerial(0, 0, 5) ' 5 minutes
Application.OnTime nSaveWB, "SaveWB"
End Sub

Public Sub SaveWB()
Alerte.Show
End Sub


In ThisWorkbook:

Private Sub workbook_open()
Alerte.Show
End Sub


In Userform: (called Alerte)

Private Sub CommandButton1_Click()
Alerte.Hide
Call SetSaveWBTimer
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Call SetSaveWBTimer
End If
End Sub


Thanks for your help.
--

Regards, Cajeto 63.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Stop vbTimer

When I open the code for ThisWorkbook and then click on Workbook in the
first pulldown then click on BeforeClose in the second pulldown, the
interface I get for Excel 2000 is

Private Sub Workbook_BeforeClose(Cancel As Boolean)

End Sub

Art


Cajeto 63 wrote:
Ozgur,
I pasted the code I have in ThisWorkbook bellow. Thanks again for your help.

Private Sub Workbook_Open()
Alerte.Show
End Sub

Private Sub workbook_BeforeClose()
Call StopTimer
End Sub
--


Regards, Cajeto 63.





"Ozgur Pars" wrote:

Cajeto,
I tried it out now and I have no problems with the before_close event.
Maybe you can post your code.

Just to set the record straight this is not my code(I wish) I found it on
the net...

Ozgur

"Cajeto 63" wrote:

Hi Ozgur,
Thank you very much for you help.

I replaced the code I was using with yours and it partially works but I get
another problem.
When I run the sub StopTimer by hand from the VB windows it stops showing
the userform which is a very good point.

But VB does not want me to use the Workbook_BeforeClose event. It gives me a
compile error saying:"Procedure declaration does not match description of
event or procedure having the same name" and I'm not sure I understand what
it means.
Could it come from the fact that I already have a Workbook_open event in the
workbook?

And if so how can I get rid of the problem?

--


Regards, Cajeto 63.





"Ozgur Pars" wrote:

Hi Cajeto63,
I use the below code to show the time on my userform. In the terminate event
of the userform I call Stoptimer so that I don't get the same problem... (you
might put it in the workbook beforeclose event)

Hope it helps,
Ozgur


Public RunWhen As Double
Public Const cRunIntervalSeconds = 60
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat, schedule:=True
End Sub


Sub The_Sub()
UserForm2.Label475.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label476.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label514.Caption = Format(Now, "dd mmm yy hh:mm")
Call StartTimer
End Sub


Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,
schedule:=False
End Sub


"Cajeto 63" wrote:

Hello Everybody,

I have copied a code for a timer in a post and applied it to my workbook to
automatically show a userform after a short period of time.
My big problem is that when I close the workbook without quitting Excel the
timer continue running and re-open my workbook after the preset period to
show the userform again.
Is there a way to have the timer stopped when closing the workbook?

My code bellow:

In Module:

Option Explicit

Public nSaveWB As Date

Public Sub SetSaveWBTimer()
nSaveWB = Now + TimeSerial(0, 0, 5) ' 5 minutes
Application.OnTime nSaveWB, "SaveWB"
End Sub

Public Sub SaveWB()
Alerte.Show
End Sub


In ThisWorkbook:

Private Sub workbook_open()
Alerte.Show
End Sub


In Userform: (called Alerte)

Private Sub CommandButton1_Click()
Alerte.Hide
Call SetSaveWBTimer
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Call SetSaveWBTimer
End If
End Sub


Thanks for your help.
--

Regards, Cajeto 63.




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Stop vbTimer

As Art pointed out, you need to use the exact declarations that Excel
expects; you cannot make up you own version.
So, it is easier to get Excel to generate them for you, by clicking those 2
drop downs and selecting the various object and events.

NickHK

"Cajeto 63" wrote in message
...
Ozgur,
I pasted the code I have in ThisWorkbook bellow. Thanks again for your

help.

Private Sub Workbook_Open()
Alerte.Show
End Sub

Private Sub workbook_BeforeClose()
Call StopTimer
End Sub
--


Regards, Cajeto 63.





"Ozgur Pars" wrote:

Cajeto,
I tried it out now and I have no problems with the before_close event.
Maybe you can post your code.

Just to set the record straight this is not my code(I wish) I found it

on
the net...

Ozgur

"Cajeto 63" wrote:

Hi Ozgur,
Thank you very much for you help.

I replaced the code I was using with yours and it partially works but

I get
another problem.
When I run the sub StopTimer by hand from the VB windows it stops

showing
the userform which is a very good point.

But VB does not want me to use the Workbook_BeforeClose event. It

gives me a
compile error saying:"Procedure declaration does not match description

of
event or procedure having the same name" and I'm not sure I understand

what
it means.
Could it come from the fact that I already have a Workbook_open event

in the
workbook?

And if so how can I get rid of the problem?

--


Regards, Cajeto 63.





"Ozgur Pars" wrote:

Hi Cajeto63,
I use the below code to show the time on my userform. In the

terminate event
of the userform I call Stoptimer so that I don't get the same

problem... (you
might put it in the workbook beforeclose event)

Hope it helps,
Ozgur


Public RunWhen As Double
Public Const cRunIntervalSeconds = 60
Public Const cRunWhat = "The_Sub"

Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,

schedule:=True
End Sub


Sub The_Sub()
UserForm2.Label475.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label476.Caption = Format(Now, "dd mmm yy hh:mm")
UserForm2.Label514.Caption = Format(Now, "dd mmm yy hh:mm")
Call StartTimer
End Sub


Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, procedu=cRunWhat,
schedule:=False
End Sub


"Cajeto 63" wrote:

Hello Everybody,

I have copied a code for a timer in a post and applied it to my

workbook to
automatically show a userform after a short period of time.
My big problem is that when I close the workbook without quitting

Excel the
timer continue running and re-open my workbook after the preset

period to
show the userform again.
Is there a way to have the timer stopped when closing the

workbook?

My code bellow:

In Module:

Option Explicit

Public nSaveWB As Date

Public Sub SetSaveWBTimer()
nSaveWB = Now + TimeSerial(0, 0, 5) ' 5 minutes
Application.OnTime nSaveWB, "SaveWB"
End Sub

Public Sub SaveWB()
Alerte.Show
End Sub


In ThisWorkbook:

Private Sub workbook_open()
Alerte.Show
End Sub


In Userform: (called Alerte)

Private Sub CommandButton1_Click()
Alerte.Hide
Call SetSaveWBTimer
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As

Integer)
If CloseMode = vbFormControlMenu Then
Call SetSaveWBTimer
End If
End Sub


Thanks for your help.
--

Regards, Cajeto 63.





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
How stop the "started office live" pop-up to stop. it is checked yrose24 Excel Discussion (Misc queries) 1 September 2nd 09 03:32 PM
To Stop or Not to Stop BillCPA Excel Discussion (Misc queries) 0 June 22nd 06 03:41 PM
How do I stop other circles in other cells to stop selecting? stauff Excel Worksheet Functions 2 October 29th 04 09:02 PM
How do I stop other circles in other boxes to stop selecting? stauff Excel Worksheet Functions 1 October 28th 04 10:27 PM
Macro: With Stop it works. Without Stop it doesn't. Don Wiss Excel Programming 2 October 12th 04 10:49 AM


All times are GMT +1. The time now is 11:12 AM.

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

About Us

"It's about Microsoft Excel"