Yakillinmesmalls
New Member
- Joined
- Feb 11, 2022
- Messages
- 8
- Office Version
- 2016
- Platform
- Windows
Hello, I am trying to create a public form within my company that users can fill out, then hit submit and it emails that completed form to all stakeholders. The problem that I am running into is that, with the VBA code that I'm using, when I click "submit", it fills out the email correctly, but the attachment is the blank excel form. How do I have the completed form attached to the email instead of the blank attachment? Here is the code that I'm running:
Private Sub CommandButton1_Click()
Dim xOutlookObj As Object
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 = "Anything you want say!" & vbNewLine & vbNewLine & _
"Here two!!" & vbNewLine & _
"Here third!!!"
On Error Resume Next
With xOutMail
.To = "Obviouslynotmyrealemail.com"
.CC = ""
.BCC = ""
.Subject = "Test. Test. Is this thing on?"
.Body = xMailBody
.Attachments.Add ActiveWorkbook.FullName
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Private Sub CommandButton1_Click()
Dim xOutlookObj As Object
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 = "Anything you want say!" & vbNewLine & vbNewLine & _
"Here two!!" & vbNewLine & _
"Here third!!!"
On Error Resume Next
With xOutMail
.To = "Obviouslynotmyrealemail.com"
.CC = ""
.BCC = ""
.Subject = "Test. Test. Is this thing on?"
.Body = xMailBody
.Attachments.Add ActiveWorkbook.FullName
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub