Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default need a Timer in an Excel Form

I need to display a running timer in an Excel form. Start the timer when the
form opens and stop the timer as the form closes.

I use frmTmr with lblTmr
I have attempted to use the Time functions with no success


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default need a Timer in an Excel Form

Pooh,

In a regular module, use

Option Explicit
Public StartTime As Date
Public RunTime As Date

Sub ShowmyForm()
Load UserForm1
UserForm1.Show
End Sub

Sub UpdateTime()
RunTime = Now + TimeValue("00:00:01")
UserForm1.TextBox1.Text = Format(Now - StartTime, "hh:mm:ss")
Application.OnTime RunTime, "UpdateTime"
End Sub


On the userform, add a textbox (Textbox1) and use

Private Sub UserForm_Deactivate()
Application.OnTime RunTime, "UpdateTime", , False
End Sub

Private Sub UserForm_Initialize()
StartTime = Now
UserForm1.TextBox1.Text = Format(Now - StartTime, "hh:mm:ss")
RunTime = Now + TimeValue("00:00:01")
Application.OnTime RunTime, "UpdateTime"
End Sub

HTH,
Bernie
MS Excel MVP


"wynnyderpooh" wrote in message
...
I need to display a running timer in an Excel form. Start the timer when the
form opens and stop the timer as the form closes.

I use frmTmr with lblTmr
I have attempted to use the Time functions with no success




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default need a Timer in an Excel Form

Bernie,
The code is great but it needs a tweak:


in Private Sub UserForm_Initialize()
in get a Compile Error; "Ambiguous name detected".

I have inserted
Option Explict
Public StartTime As Date
Public RunTime As Date in the module and in the form initialize event code.

Can you help?
Thanks,
wynnyderpooh


"Bernie Deitrick" wrote:

Pooh,

In a regular module, use

Option Explicit
Public StartTime As Date
Public RunTime As Date

Sub ShowmyForm()
Load UserForm1
UserForm1.Show
End Sub

Sub UpdateTime()
RunTime = Now + TimeValue("00:00:01")
UserForm1.TextBox1.Text = Format(Now - StartTime, "hh:mm:ss")
Application.OnTime RunTime, "UpdateTime"
End Sub


On the userform, add a textbox (Textbox1) and use

Private Sub UserForm_Deactivate()
Application.OnTime RunTime, "UpdateTime", , False
End Sub

Private Sub UserForm_Initialize()
StartTime = Now
UserForm1.TextBox1.Text = Format(Now - StartTime, "hh:mm:ss")
RunTime = Now + TimeValue("00:00:01")
Application.OnTime RunTime, "UpdateTime"
End Sub

HTH,
Bernie
MS Excel MVP


"wynnyderpooh" wrote in message
...
I need to display a running timer in an Excel form. Start the timer when the
form opens and stop the timer as the form closes.

I use frmTmr with lblTmr
I have attempted to use the Time functions with no success





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default need a Timer in an Excel Form

in get a Compile Error; "Ambiguous name detected".

If you already have a procedure named "UserForm_Initialize", replace
it with Bernie's code or merge his code into yours. You can have only
one procedure named "UserForm_Initialize".

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Wed, 11 Mar 2009 11:16:05 -0700, wynnyderpooh
wrote:

Bernie,
The code is great but it needs a tweak:


in Private Sub UserForm_Initialize()
in get a Compile Error; "Ambiguous name detected".

I have inserted
Option Explict
Public StartTime As Date
Public RunTime As Date in the module and in the form initialize event code.

Can you help?
Thanks,
wynnyderpooh


"Bernie Deitrick" wrote:

Pooh,

In a regular module, use

Option Explicit
Public StartTime As Date
Public RunTime As Date

Sub ShowmyForm()
Load UserForm1
UserForm1.Show
End Sub

Sub UpdateTime()
RunTime = Now + TimeValue("00:00:01")
UserForm1.TextBox1.Text = Format(Now - StartTime, "hh:mm:ss")
Application.OnTime RunTime, "UpdateTime"
End Sub


On the userform, add a textbox (Textbox1) and use

Private Sub UserForm_Deactivate()
Application.OnTime RunTime, "UpdateTime", , False
End Sub

Private Sub UserForm_Initialize()
StartTime = Now
UserForm1.TextBox1.Text = Format(Now - StartTime, "hh:mm:ss")
RunTime = Now + TimeValue("00:00:01")
Application.OnTime RunTime, "UpdateTime"
End Sub

HTH,
Bernie
MS Excel MVP


"wynnyderpooh" wrote in message
...
I need to display a running timer in an Excel form. Start the timer when the
form opens and stop the timer as the form closes.

I use frmTmr with lblTmr
I have attempted to use the Time functions with no success





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default need a Timer in an Excel Form

Yeah...what Chip said. (Of course!)

And you should only declare your variables once, at the top of your regular
codemodule.

HTH,
Bernie
MS Excel MVP

"wynnyderpooh" wrote in message
...
Bernie,
The code is great but it needs a tweak:


in Private Sub UserForm_Initialize()
in get a Compile Error; "Ambiguous name detected".

I have inserted
Option Explict
Public StartTime As Date
Public RunTime As Date in the module and in the form initialize event
code.

Can you help?
Thanks,
wynnyderpooh


"Bernie Deitrick" wrote:

Pooh,

In a regular module, use

Option Explicit
Public StartTime As Date
Public RunTime As Date

Sub ShowmyForm()
Load UserForm1
UserForm1.Show
End Sub

Sub UpdateTime()
RunTime = Now + TimeValue("00:00:01")
UserForm1.TextBox1.Text = Format(Now - StartTime, "hh:mm:ss")
Application.OnTime RunTime, "UpdateTime"
End Sub


On the userform, add a textbox (Textbox1) and use

Private Sub UserForm_Deactivate()
Application.OnTime RunTime, "UpdateTime", , False
End Sub

Private Sub UserForm_Initialize()
StartTime = Now
UserForm1.TextBox1.Text = Format(Now - StartTime, "hh:mm:ss")
RunTime = Now + TimeValue("00:00:01")
Application.OnTime RunTime, "UpdateTime"
End Sub

HTH,
Bernie
MS Excel MVP


"wynnyderpooh" wrote in message
...
I need to display a running timer in an Excel form. Start the timer when
the
form opens and stop the timer as the form closes.

I use frmTmr with lblTmr
I have attempted to use the Time functions with no success






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
Timer to flash msg on a form Les Stout[_2_] Excel Programming 8 July 11th 07 08:10 PM
Timer in Excel FloMM2 Excel Programming 5 September 4th 06 09:58 PM
Stopping a Timer / Running a timer simultaneously on Excel Paul23 Excel Discussion (Misc queries) 1 March 10th 06 12:08 PM
EXCEL 2002: How do I user/simulate a Timer event in Excel form JohnF[_2_] Excel Programming 12 September 23rd 04 04:56 PM
EXCEL 2002: How do I user/simulate a Timer event in Excel form John Fejsa Excel Programming 2 August 18th 04 03:44 AM


All times are GMT +1. The time now is 09:50 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"