1

I have written a VBA script in Outlook 2016 and it works when I run it from Outlook. I now want to be able to run the script through a bat file, so that I can use Task Scheduler to run the script daily without my input. I don't seem to be able to run scripts through Rules on my version of Outlook.

I've tried the following in the cmd line, but it only opens a new instance of Outlook and doesn't run the script.

"C:\filepath\OUTLOOK.EXE" /autorun ScriptName

After some digging, I don't think /autorun is supported by the version of Outlook I'm using, but I can't seem to find what replaced it.

I would like to be able to run the script automatically once a day, though it doesn't have to include Task Scheduler if there is an easier way.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
ARL
  • 64
  • 8
  • Is the computer going to stay online 24/7? Otherwise... I don't know about outlook that much but in excel you can just write a macro on the `Workbook_Open` event which is `Application.OnTime("10:00:00"), "YourProcedure"` and it would run. If there is a way to do that in outlook that should be the way. If not, try writting the script on Excel and do as I suggested. – Damian Apr 02 '19 at 14:28
  • Right now my computer isn't online 24/7, but if i can get this to work I might get the resources to get a computer that will be. What you're suggesting is to forgo Task Scheduler all together and just set the Outlook Script to run at set time each day? The limitation to this is that Outlook would have to be open and the computer logged on, correct? – ARL Apr 02 '19 at 14:33
  • You could use the Task Scheduler to open the outlook. If what needs to be done can be done just after openning outlook, forget about time execution and fire it on Outlook_Open event, if it exists. – Damian Apr 02 '19 at 14:35
  • I just checked. Put your code on `Private Sub Application_Startup()` on the `ThisOutlookSession` Object and it will run on Outlook start, then place a task to open Outlook on windows start and you are all set. I guess. – Damian Apr 02 '19 at 14:37
  • What you described I think would work, but I generally leave my computer asleep at night with outlook open for days. As I'd need to manually open and close Outlook, adding a button to the ribbon that runs the script would be a similar solution. Thank you very much for your suggestions- they have given me a new way to think of this problem. – ARL Apr 02 '19 at 14:50
  • Is this what your trying to do? https://stackoverflow.com/a/40144594/4539709 – 0m3r Apr 02 '19 at 23:18

0 Answers0