I have a VBA to automate generation of emails on Outlook with attachments. The query used to work OK but I now get the following error: Compile error. Cannot find project or library.
Not sure how to fix this so any help would be great. The VBA code is:
Sub Display_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 = OutApp.CreateItemFromTemplate("C:\Users\SITA\Desktop\test template.oft")
On Error Resume Next
With NewMail
.To = Cells(i, 2).Value
.Attachments.Add Cells(i, 3).Value
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Excel file:
Not sure how to fix this so any help would be great. The VBA code is:
Sub Display_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 = OutApp.CreateItemFromTemplate("C:\Users\SITA\Desktop\test template.oft")
On Error Resume Next
With NewMail
.To = Cells(i, 2).Value
.Attachments.Add Cells(i, 3).Value
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Excel file: