.
Presuming the email macro you posted functions as desired, the following edits will attach a pdf file
and display the email prior to sending.
Code:
Option Explicit
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 = "Below is my test results." & vbNewLine & vbNewLine & _
"The required pass mark is 90%." & vbNewLine & _
"I received " & Range("F51").Value & "%." & vbNewLine & _
"My incorrect answers were" & Range("F55").Value & ""
On Error Resume Next
With xOutMail
.To = [f52].Value
.CC = ""
.BCC = ""
.Subject = "My Test Results"
.Body = xMailBody
.Attachments.Add "C:\Users\My\Desktop\MyPDFFile.pdf" '<--- Change MY to name of your computer and name of pdf file
' pdf file is being stored on your desktop.
' you can change path to any location desired.
'.Send
.Display
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
Alrighty, so I was able to come up with the following coding which now populates the pop up email but I was unable to get it to add an attachment of the current workbook:
Sub Testemailsend()
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 = "Test Email Body." & vbNewLine & _
"Test Email Body." & vbNewLine & _
"Test Email Body." & Range("F51").Value & "" & vbNewLine & _
"Test Email Body." & Range("F55").Value & ""
On Error Resume Next
With xOutMail
.To = [f52].Value
.CC = ""
.BCC = ""
.Subject = "Test Email Subject"
.Body = xMailBody
.Attachments.Add "\\mau.group\corporate\Homefolders$\rlakmas\Desktop"
'.Send
.Display
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
I guess another way for me to explain what it is that i'm trying to make it look like is once the user presses the macro button, it replicates the following process:
File > Save & Send > Send Using E-mail > Send As Attachment
When that pop up appears, the Subject and Body just have some pre-filled information similar to my coding above.
I feel like I may be over complicating the process but I can't imagine it's this hard to code it.
(Example of coding I found that doesn't work out of the box and needs Debugging and doesn't work quite right:
https://www.thespreadsheetguru.com/blog/vba-guide-sending-excel-attachments-through-outlook)