Run macro ever 5 seconds and turn off?

S

Shaka215

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!
 
C

Chip Pearson

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top