What security settings do I have to change to allow Excel VBA to automatically create and send MS Outlook emails?
Version: MS Office 2016 Pro Plus
VBA Reference: Microsoft Office 16.0 Object Library
I created an excel VBA script that sends an MS Outlook email, but it always gives me a runtime error 287 when it gets to the send line.
I am using the Microsoft Office 16.0 Object Library.
I read a few times that I need to change my security settings on my MS Outlook before this can work, but I've yet to find which settings those are.
What are the specific settings that would allow for this line of code to work?
Also, I want to pass this tool around in my workplace, but I think adoption would be impacted if I added a few confusing steps that required the user to navigate their outlook settings (adoption behavior: if it isn't familiar or extremely simple it will not be used). Is there a better way to get around this step (outside of baking a sendkey script into the tool or having each person fiddle with their settings)?
SCRIPT:
Sub Send_email()
'Test email to self using MS OUTLOOK 16.0 Object Library (Tools > References > MS OUTLOOK 16.0 Object Library)
'Developer Note: There is a MS Office 16.0 VS MS Outlook 16.0. They look deceptively similar and has caused no small issue for many users.
Dim OutlookApp As Outlook.Application
Dim OutlookMail As Outlook.MailItem
Set OutlookApp = New Outlook.Application
Set OutlookMail = OutlookApp.CreateItem(olMailItem)
Set ws = Worksheets("Sheet3")
With OutlookMail
.BodyFormat = olFormatHTML
.Display
.HTMLBody = "This is an autosend test email from excel" & "<br>" & "Thank you," & "<br>" & "muddled_modron"
.To = "******@email.com"
'.CC = "******@email.com"
'.BCC = ""
.Subject = "Test AutoEmail"
'.Send
End With
End Sub