HI,
I came across this code to add a command button which i can press to send my work via email. It works perfectly for the way it was designed, but that is to attach the sheet as an attachment.
Given it's only a few cells of data, I'm wanting to include it in the body of the email, rather than as an attachment.
this is the code (i tried removing the .attachments.add... line but that just sends nothing)
Private Sub CommandButton1_Click()
'Updated by Extendoffice 2017/9/14
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
ActiveWorkbook.Save
xMailBody = "Body content" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2"
On Error Resume Next
With xOutMail
.To = "Ash.D@freight.com"
.CC = ""
.BCC = ""
.Subject = "Shipment update for " & [B2]
.Body = xMailBody
.Attachments.Add ActiveWorkbook.FullName
.Display 'or use .Display
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
I came across this code to add a command button which i can press to send my work via email. It works perfectly for the way it was designed, but that is to attach the sheet as an attachment.
Given it's only a few cells of data, I'm wanting to include it in the body of the email, rather than as an attachment.
this is the code (i tried removing the .attachments.add... line but that just sends nothing)
Private Sub CommandButton1_Click()
'Updated by Extendoffice 2017/9/14
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
ActiveWorkbook.Save
xMailBody = "Body content" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2"
On Error Resume Next
With xOutMail
.To = "Ash.D@freight.com"
.CC = ""
.BCC = ""
.Subject = "Shipment update for " & [B2]
.Body = xMailBody
.Attachments.Add ActiveWorkbook.FullName
.Display 'or use .Display
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub