ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run macro ever 5 seconds and turn off? (https://www.excelbanter.com/excel-programming/396780-run-macro-ever-5-seconds-turn-off.html)

[email protected]

Run macro ever 5 seconds and turn off?
 
Hi everyone!

I was hoping to get some feedback on how to get a macro to run every 5
seconds and turn it's self off when it's done doing what it has to?

What I am trying to do is get a webbrowser object to refresh it's self
every 5 seconds...but I need it so that someone can still use the
userform I created instead of causing Excel to lockup ever 5
seconds... I tried the following code...

Private Sub UserForm_Activate()
Do Until Now = Now + TimeValue("00:00:05")
WebBrowser1.Navigate ("C:\www.Cnn.com")
Loop
End Sub


Any ideas would be greatly appreciated.

Thank you!


Chip Pearson

Run macro ever 5 seconds and turn off?
 
The code

Do Until Now = Now + TimeValue("00:00:05")

will never be true. Every time that line of code runs, Now gets a new value
and Now will never be equal to Now + 5 seconds.

See www.cpearson.com/Excel/OnTime.htm for details about using the OnTime
method.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


wrote in message
oups.com...
Hi everyone!

I was hoping to get some feedback on how to get a macro to run every 5
seconds and turn it's self off when it's done doing what it has to?

What I am trying to do is get a webbrowser object to refresh it's self
every 5 seconds...but I need it so that someone can still use the
userform I created instead of causing Excel to lockup ever 5
seconds... I tried the following code...

Private Sub UserForm_Activate()
Do Until Now = Now + TimeValue("00:00:05")
WebBrowser1.Navigate ("C:\www.Cnn.com")
Loop
End Sub


Any ideas would be greatly appreciated.

Thank you!




All times are GMT +1. The time now is 11:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com