Reputation: 11791
This scripts works just fine when I manually open the db and run the script. But when I use the task to start it, I get error 429 'ActiveX component can't create object' on the 2nd line of:
Dim OlApp As Outlook.Application
Set OlApp = CreateObject("Outlook.Application")
Why does this throw an error when initiated by the task scheduler, but run fine manually?
Found an MS Support article on this very subject. It specifically states that CreateObject
and CoCreateInstance
will fail will the above error message if used in this way. However, no alternative is given.
Any suggestions, please?
Upvotes: 0
Views: 14060
Reputation: 66276
No Office app, Outlook included, can be used from a service. Even if the task can interact with the desktop, the COM system will not let you connect to a running COM object (Outlook is a singleton) since the security contexts are different.
You can use Extended MAPI (C++ or Delphi), CDO 1.21 (deprecated and is no longer updated or installed) or Redemption (I am its author - use the RDO family of objects) - all of these load the Extended MAPI system in-proc instead of connecting to an out-of-proc COM object (exposed by outlook.exe).
Upvotes: 2
Reputation: 1
I have found a solution to your problem, The VBScript interpreter (cscript.exe/wscript.exe) comes with a 64-bit version of Windows and a 32-bit version.
What I did was installed the Office x86 then uninstalled then installed x64 tested emails from task scheduler working, then I reinstalled x86. I did restart after each install and uninstall. When you install the x64 and x86 version of office it will install both versions cscript.exe/wscript.exe x86 and x64. Which in the end allows you to send a mail from task scheduler (Tested on Windows 10).
Thanks
Upvotes: 0
Reputation: 123779
When sending email messages from VBA code I have always preferred to use CDO instead of trying to automate Outlook. For some sample code to send email messages via CDO, look here.
Upvotes: 1