Schedule Outlook 2003 Macro
Asked Answered
I

2

4

I have an Outlook 2003 macro written in VBA.

I would like to schedule it so that it automatically runs at a certain time, say 01:00. The PC is always logged on.

I couldn't find anything which suggests how to do this.

Instep answered 10/2, 2012 at 10:29 Comment(2)
Can you clarify the question? I don't think I understand. You can run the macros in precisely the way described. Although obviously there is no "RunMacro" function. Can you post actual code?Yester
Well, other than the macro there isn't any code. I have a macro which I need to run on a scheduled basis. I just need to know how I can schedule this. I have no doubt there is a way, but I don't know what it is.Instep
V
6

You could create a scheduled task on the PC to run daily at the specific time, and use the Outlook Command Line Switch to start the program and call your macro e.g:

"C:\Program Files\Microsoft Office\Office11\Outlook.exe" /autorun macroname

Update:

You may be able to use an API call to start a timer to run in the background of outlook, you could combine this with the VB Now() command to get the current time and if greater than your scheduling time you could trigger your macro, the API example can be found here:

http://www.outlookcode.com/threads.aspx?forumid=4&messageid=22831

Vicegerent answered 13/2, 2012 at 13:42 Comment(5)
Thanks for the answer. The only problem with this approach is that this instance of Outlook must be running 24 hours. There are several rules which need to react to incoming mail, and this has to continue until I can replace it with something else, which I am working on.Instep
@bukko No worries, I've added an update with a link to another possible approach for when Outlook is constantly running.Vicegerent
The example you linked to is for Outlook 2007 - do you know if that will work with Outlook 2003? I can't see a ThisOutlookSession module in the VB editor - do I need to add one? Thanks for the help so far :)Instep
A bit fiddly but I think that's done it. Thanks for your help - so many people said it couldn't be done :)Instep
@bukko That's ok, Ive always found Outlook to be a little more awkward for VB than the other apps but if it can be done then it's definately somewhere on outlookcode.com : )Vicegerent
Y
-1

http://support.microsoft.com/kb/237913/EN-US

This article says it can't be done unless you rewrite it to use CDO.

Sorry.

Yester answered 13/2, 2012 at 22:7 Comment(3)
It says you can't run Outlook as a service, but there are other ways, especially as the Outlook user will always be logged on. I'm currently exploring the timer option above which looks like it could work.Instep
Yup, exactly as I said. However I managed to do it thanks to the answer above.Instep
I meant to paste this, sorry: support.microsoft.com/kb/290654 FTA: If you are using Windows NT or Windows 2000, the Task Scheduler runs in a service. You cannot automate the Outlook object model from a service, or a process that is spawned from a service.Yester

© 2022 - 2024 — McMap. All rights reserved.