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
 

Some videos you may like

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
3,948
.
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
 

lxondecks

New Member
Joined
Sep 23, 2020
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,126,893
Messages
5,621,486
Members
415,844
Latest member
Reda Fouad Ramzy

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
Top