I have a list of Data that contains various entry details (Made by, Date, Amount, etc.) stored on a excel worksheet. I am trying to auto support to people who made the entries in the first place.
My goals for the macro I'm writing are:
This what I have to far:
Sub SendMail()
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim blRunning As Boolean
blRunning = True
on Error Resume Next
Set olApp = GetObject (,"Outlook.Application")
If olApp Is Nothing Then
Set olApp = New Outlook.Application
blRunning = False
End If
On Error GoTo 0
Set olMail = olApp.CreateItem(olMailItem)
With olMail
.Subject = "Automatic Entry Support"
.Recipients.Add "J.Doe@gmail.com"
.Attachments.Add "C:\Users\J.Doe\Documents\Project\Template draft.xlsx"
.Body = "Support message"
.Display ("Spell check, data attached?, SEND")
End With
If Not blRunning Then olApp.Quit
Set olApp = Nothing
Set olMail = Nothing
End Sub
(There are lines in the code that I placed with "fake" lines to not show anything important).
Also, this is my first post on this site so please comment if I am not asking the question in the right format.
UPDATE : I am also receiving an error when trying to run the code: "Run-time error '-2147024894 (8007002): Automation error"
.Body = "Support message"
You may try to set the BodyFormat
before setting the message body.
Most probably you have faced with a security issue in Outlook. "Security" in this context refers to the so-called "object model guard" that triggers security prompts and blocks access to certain features in an effort to prevent malicious programs from harvesting email addresses from Outlook data and using Outlook to propagate viruses and spam.
Possible workarounds are:
Globals.ThisAddin.Application
object.Read more about possible options in the Outlook "Object Model Guard" Security Issues for Developers article.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.