Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Sub SendMail()
Dim oOutlook As Object
Dim oMailItem As Object
On Error GoTo SendMail_Err
Set oOutlook = CreateObject("Outlook.Application")
Set oMailItem = oOutlook.CreateItem(olMailItem)
With oMailItem
.To = "Email@somthing.com"
.Subject = "Bow Chicka Wow Wow"
.Body = "My big chicken is awesome."
.Send
End With
'Tidy Up
Set oOutlook = Nothing
Set oMailItem = Nothing
Exit Sub
SendMail_Err:
MsgBox "No Worky"
End Sub
Sub main
SendMail
End sub
Sub Main()
Dim oOutlook As Object
Dim oMailItem As Object
On Error GoTo SendMail_Err
Set oOutlook = CreateObject("Outlook.Application")
Set oMailItem = oOutlook.CreateItem(olMailItem)
With oMailItem
.To = "myemail@mts.net"
.Subject = "Email Test"
.Body = "This email was sent from a macro."
.Display
End With
'Tidy Up
Set oOutlook = Nothing
Set oMailItem = Nothing
Exit Sub
SendMail_Err:
MsgBox "ERROR!"
End Sub
RPEN said:Ok, I think I've got it, I just changed ".Send" to ".Display". It works, the email comes up, but I'm getting this error on the line that has ".Display":
no such property or method
Line number: 42
Stopping macro playback
Any idea why I'm getting this error?
Christadelphian said:Does anyone know, would the text for the main body of the email have to be stipulated in a string, and called in a function?
Or is there a simpler way to get Outlook to recognise a new line?
With oMailItem
.To = "youremail@domain.com"
.Subject = "Your Subject"
.Body = "Good Day," & Chr(13) & Chr(13) & _
"Please be advised blah blah blah......" & Chr(13) & _
"If we have not recieved blah blah blah......."
.Display
End With
With oMailItem
.To = "youremail@domain.com"
.Subject = "Your Subject"
.BodyFormat = 2 'HTML format
.HTMLBody = "Good Day,<br><br>" & _
"Please be advised blah blah blah......<br>" & _
"If we have not recieved blah blah blah.......<br>"
.Display
End With