Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA within Outlook Compile error

Status
Not open for further replies.

eit09

Civil/Environmental
Jul 8, 2009
183

I have used this coding bellow in the past but now I am getting a Compile error. looking for some guidance how to change this coding to get around the compile error.




Sub Sendoffice365invoice()

Dim myItem As Outlook.MailItem
Dim myolApp As Outlook.Application
Dim myRecipient As Recipient



Set myolApp = CreateObject("Outlook.Application")
Set myItem = myolApp.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments

myAttachments.Add "H:\Office 365 Invoice\Office 365 Business Premium Invoice.pdf"
myAttachments.Add "H:\Office 365 Invoice\Office 365 Exchange online plan Invoice .pdf"

With myItem
.Importance = olImportanceNormal
.Subject = "Office 365 Invoice"





.Display 'optional
End With


End Sub
 
 https://files.engineering.com/getfile.aspx?folder=a42ca6f0-0af2-4e11-812a-79c21be69b1d&file=Compile_Error.JPG
Replies continue below

Recommended for you

I try run that code in outlook 2016/365 and it works fine if I comment out the .add attachments part?

For some reason it didn't work (with a different error) until I saved it to the project.

I get the same error as you running it under excel, so perhaps you don't have the required references loaded into the project or are missing one, refer under tools/references? (FYI I have the following enabled if it helps)

Untitled_wkl4r0.png
 
Agent666,

Thanks for trying on your machine at least I know the code works. I did check my settings and they were the same so removed 365 and reinstalled with no luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor