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.

John Coleman
  • 51,337
  • 7
  • 54
  • 119
CompanyDroneFromSector7G
  • 4,291
  • 13
  • 54
  • 97
  • 1
    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? – Nathan Rice Feb 11 '12 at 18:59
  • 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. – CompanyDroneFromSector7G Feb 12 '12 at 20:33

2 Answers2

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

Matt Donnan
  • 4,933
  • 3
  • 20
  • 32
  • 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. – CompanyDroneFromSector7G Feb 13 '12 at 14:10
  • @bukko No worries, I've added an update with a link to another possible approach for when Outlook is constantly running. – Matt Donnan Feb 13 '12 at 14:57
  • 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 :) – CompanyDroneFromSector7G Feb 13 '12 at 15:08
  • A bit fiddly but I think that's done it. Thanks for your help - so many people said it couldn't be done :) – CompanyDroneFromSector7G Feb 14 '12 at 17:14
  • @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 http://www.outlookcode.com : ) – Matt Donnan Feb 15 '12 at 09:08
-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.

Nathan Rice
  • 3,091
  • 1
  • 20
  • 30
  • 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. – CompanyDroneFromSector7G Feb 14 '12 at 10:04
  • Yup, exactly as I said. However I managed to do it thanks to the answer above. – CompanyDroneFromSector7G Feb 14 '12 at 17:16
  • I meant to paste this, sorry: http://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. – Nathan Rice Feb 14 '12 at 17:19