VBA - compile error. cannot find project or library

ssh99

New Member
Joined
Oct 25, 2020
Messages
36
Office Version
  1. 2010
Platform
  1. Windows
  2. MacOS
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:
1720956320992.png
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi 99,
may be it helps to set Microsoft Office 16.0 Object Library or Microsoft Outlook 16.0 Object Library in the references or the VBE?
Best wishes
Senior Newbie
 
Upvote 0
Hi 99,
may be it helps to set Microsoft Office 16.0 Object Library or Microsoft Outlook 16.0 Object Library in the references or the VBE?
Best wishes
Senior Newbie
Thanks for your reply. Microsoft Office 16.0 is already selected from what I can see...
1720969595884.png
 
Last edited:
Upvote 0
Open the VBE (aka Visual Basic Editor) by Alt+F11. Go to menu bar > Extras > References and select the two proposed referenceses. Consider: This reference is only available for your active workbook.
 
Upvote 0
okay - then
  1. deactivate the lines on error ...
  2. debug the code line by line with F8
  3. and btw: there's no chance to help with only a part of the code. So helpers can only guess, bu not find the problem
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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