In the Visual Basic Editor, select Tools > References...
Scroll down the list until you see Microsoft Outlook 16.0 Object Library.
Tick its check box, then click OK.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I would like to use the following code to send an email notification when the spreadsheet is changed, but I am getting an error 'User-defined type not defined'
Can you help me?
' Creates email
' Requires Outlook library (References > Microsoft Outlook 16.0 Object Library)
Sub SendMail()
On Error GoTo ErrorHandler
' Outlook variables
Dim **olApp As Outlook.Application**, olMail As Outlook.MailItem
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)
' Message
Dim strMessage As String
strMessage = "Placeholder"
' Email body
Dim strBody As String
strBody = "<body font-size: 11pt><p>" & \_
strMessage & "</p></body>"
' Displays email
olMail.Display
' Stores signature
Dim strSig As String
strSig = Replace(olMail.HTMLBody, "<p class=MsoNormal><o:p> </o:p></p>", "")
' Creates email
With olMail
.To = "******@customheli.com"
.Recipients.ResolveAll
.Subject = "Placeholder"
.BodyFormat = olFormatHTML
.HTMLBody = strBody & strSig
End With
Exit Sub
ErrorHandler:
MsgBox "Error when creating email. Please try again or send the email manually.", vbOKOnly, "Error"
End Sub
Sub Test()
End Sub
Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.
That is the Microsoft Office 16.0 Object library, not the Microsoft Outlook 16.0 Object Library.
My bad! Thank you :)