Hi, I built a simple form with VBA that auto sends an email of the form when clicked. The problem is the form is sending a blank sheet, rather than a populated one and I have no idea why. Any ideas? Code is below.
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)
xMailBody = "Body content" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2"
On Error Resume Next
With xOutMail
.To = "person2"
.CC = "person1"
.BCC = ""
.Subject = "RTO " & Range("D6 ") & " " & Range("D10 ") & " " & Range("D11")
.Body = "Hello," & " " & Range("D2") & ", please repond to all with confirmed order number, load date, and time."
.Attachments.Add ActiveWorkbook.FullName
.Send 'or use .Display
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
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)
xMailBody = "Body content" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2"
On Error Resume Next
With xOutMail
.To = "person2"
.CC = "person1"
.BCC = ""
.Subject = "RTO " & Range("D6 ") & " " & Range("D10 ") & " " & Range("D11")
.Body = "Hello," & " " & Range("D2") & ", please repond to all with confirmed order number, load date, and time."
.Attachments.Add ActiveWorkbook.FullName
.Send 'or use .Display
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub