Automate a Macro?

I have an outlook  macro that I created and I would like to run it every 5 mins. Is this possible?
I try to use the /autorun switch but it does not kick off my macro. I figure that the name of the macro is not correct .. how can I tell what name the command line is looking for. Thanks!
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.

Hi bmickey,

There are ways of getting a macro to run automatically (not using the /autorun commandline switch). Some can run at set intervals (5 minutes) and are very complex and possibly unstable, others can run at specific events of the program which usually work much more in your favor.  

Before I go into any specifics, what are you trying to do/accomplish? What does your macro do that you want it run every 5?

bmickeyAuthor Commented:
we have a folder that has some emails in it and if an email has been in that folder longer than 30 mins then send an email out letting someone know... that's what we are trying to do.
Ok.. I have what you can do to get this to work at 5 minute intervals, though I'm also brainstorming as to a more streamlined way to what you want to accomplish. For now, here is some code that will do what you want, and I'll post back later (tomorrow) if I can work through all the details in my head.

The following goes into a standard code module.  Look for the line that has "***** CHANGE THIS LINE TO THE NAME OF YOUR MACRO" as a comment, and change YourMacroName to be the name of your macro that you want to automate.

You'll have to call the StartAutoRun macro to start the automatic processing, and call StopAutoRun to stop it.  You can easily do this in your Application_Startup and Application_Quit events in your ThisOutlookSession class module.

I'll post back tomorrow either way after thinking more about this
Option Explicit
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal _
  nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal _
  nIDEvent As Long) As Long
Public Const DELAY_MILLISECONDS As Long = 300000 '5 minutes = 300000 MS
Public KeepGoing As Boolean
Public pbnIDEvent As Long
Sub RunMacro(ByVal hwnd As Long, ByVal uMsg As Long, ByVal nIDEvent As Long, _
  ByVal dwTimer As Long)
 pbnIDEvent = nIDEvent
 If KeepGoing Then
 End If
 If Not KeepGoing Then KillTimer 0&, nIDEvent
End Sub
Sub StartAutoRun()
 KeepGoing = True
 SetTimer 0&, 0&, DELAY_MILLISECONDS&, AddressOf RunMacro
End Sub
Sub StopAutoRun()
 KillTimer 0&, pbnIDEvent
 KeepGoing = False
End Sub

Open in new window


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
Hi again,

I did a bit of thinking about this, and I think using the method above would be the best way to do this. I tried writing it in a way that checked each message as it came in and assigning it an expiration time (after initially checking to see if any messages were 'expired'), but it proved to be no better than the way I have it above.

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

From novice to tech pro — start learning today.