Creating a Timer/Loop inside a Macro

Hi, I'm using MS Word 2003. I would like to create a Loop within one my macros that executes or Loops on a timed basis. In other words, once I trigger my macro, I'd like something within the macro to happen every 15 minutes.

For example, lets say I wanted to print my document every 15 minutes. So, I have my print command within my macro, which is simple to set up. Now I want to put that print event inside a Loop that fires every 15 minutes. In the end I'd be printing my document every 15 minutes as long as my macro is running.

What would be the best way to do that?

Thanks,
Fulano
Mr_FulanoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ingeborg Hawighorst (Microsoft MVP / EE MVE)Microsoft MVP ExcelCommented:
Hello,

this code goes into several modules, to automatically kick in when the workbook is opened.

cheers, teylyn
' Code for the ThisWorkbook module
Private Sub Workbook_BeforeClose(Cancel As Boolean)

     Application.OnTime dTime, "MyTimer", , False

End Sub



Private Sub Workbook_Open()

  Application.OnTime Now + TimeValue("00:15:00"), "MyTimer"

End Sub



' this code goes in a standard module

Public dTime As Date
Sub MyTimer()
dTime = Now + TimeValue("00:15:00")
Application.OnTime dTime, "MyTimer"


'put your code here
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mr_FulanoAuthor Commented:
Hi teylyn, OK...that worked. How do I stop it if I want to stop it without closing the document?

Thanks for the help!
Fulano
0
Ingeborg Hawighorst (Microsoft MVP / EE MVE)Microsoft MVP ExcelCommented:
You need to run another macro to stop the timer. You could add a form button or a shape to the sheet and assign the macro below to that button.

cheers, teylyn


Sub StopMyTimer()
    Application.OnTime dTime, "MyTimer", , False 
End Sub

Open in new window

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Mr_FulanoAuthor Commented:
Very good...thank you!!!

Fulano
0
Mr_FulanoAuthor Commented:
Excellent work!
0
Ingeborg Hawighorst (Microsoft MVP / EE MVE)Microsoft MVP ExcelCommented:
Thanks for the grade!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.