VBA Send mail not working with Task Scheduler

lxondecks

New Member
Joined
Sep 23, 2020
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Hi Guys,

I am trying to use the below code to send an Excel workbook via email.
The code works perfectly fine when manually running the macro, or with task scheduler set to "Run only when user is logged on"

However when change to "Run whether user is logged on or not" or Tick "run with highest privileges"
I get a Runtime Error 429 ActiveX cant create object
Any assistance would be much appreciated.


Dim OutlookApp As Object
Dim OutlookMail As Object
Set OutlookApp = CreateObject("Outlook.Application")

Set OutlookMail = OutlookApp.CreateItem(0)
On Error Resume Next
With OutlookMail
.To = ""
.CC = ""
.BCC = ""
.Subject = ""
.Body = "."
.Attachments.Add Application.ActiveWorkbook.FullName
.Send
End With
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
.
I tried your macro with SEND and with DISPLAY. Both worked fine here.

VBA Code:
Option Explicit

Sub sndmail()
Dim OutlookApp As Object
Dim OutlookMail As Object

Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)

On Error Resume Next
    
    With OutlookMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = ""
        .Body = "."
        .Attachments.Add Application.ActiveWorkbook.FullName
        .Send
    End With
    
Set OutlookMail = Nothing
Set OutlookApp = Nothing

End Sub
 
Upvote 0
Thanks. Yes the macro seems fine when running manually. But when I setup a task scheduler so that the workbook is opened automatically I get a runtime 429 error.

I read somewhere it may be caused by outlook being already open, but I've not managed to find a resolution.
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,375
Members
448,955
Latest member
BatCoder

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top