I have a script I use to automate sending emails on Outlook. It works fine but I now want it to send the emails using a template. I have added the 'NewMail as Outlook.Object' line to the code to try and do this but get the following error: Run-Time Error 424: Object Required. I have checked the file mapping for the template to be used and it is correct. Can anyone help resolve this?
The VBA code is:
The VBA code is:
VBA Code:
Sub Send_Emails()
Dim OutApp As Object
Dim OutMail As Object
Dim OutAccount As Outlook.Account
Dim NewMail As Outlook.MailItem
For i = 2 To Sheet1.Cells(Rows.Count, 2).End(xlUp).Row
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set OutAccount = OutApp.Session.Accounts.Item(1)
Set NewMail = obApp.CreateItemFromTemplate("G:\Shared\test")
On Error Resume Next
With NewMail
.To = Cells(i, 2).Value
.Attachments.Add Cells(i, 3).Value
.Importance = olImportanceHigh
.OriginatorDeliveryReportRequested = True
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Next
End Sub
Last edited by a moderator: