marcusja2002
Board Regular
- Joined
- Apr 27, 2010
- Messages
- 107
I have put together the below code to email a document out. ******@******.com represents my email address.
The code works well, in that it creates a PDF, emails it to me then deletes the pdf. The problem is the PDF is of the excel worksheet not the User form I created.
What can I change to capture the form and send that via email.
Private Sub btnsendemail_Click()
Dim Mail As New Message
Dim Config As Configuration
Dim KillFile As String
Set Config = Mail.Configuration
ChDir "C:\temp"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\temp\Book1.pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
Config(cdoSendUsingMethod) = cdoSendUsingPort
Config(cdoSMTPServer) = "smtp.office365.com"
Config(cdoSMTPServerPort) = 25
Config(cdoSMTPAuthenticate) = cdoBasic
Config(cdoSMTPUseSSL) = True
Config(cdoSendUserName) = "******@******.com"
Config(cdoSendPassword) = "**********"
Config.Fields.Update
Mail.To = "******@******.com"
Mail.From = Config(cdoSendUserName)
Mail.Subject = "Email Subject"
Mail.HTMLBody = "<b>Email Body</b>"
Mail.AddAttachment "C:\temp\Book1.pdf"
On Error Resume Next
Mail.Send
If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical, "There was an error"
Exit Sub
End If
MsgBox "Your email has been sent", vbInformation, "Sent"
KillFile = "C:\temp\Book1.pdf"
'Check that file exists
If Len(Dir$(KillFile)) > 0 Then
'First remove readonly attribute, if set
SetAttr KillFile, vbNormal
'Then delete the file
Kill KillFile
End If
End Sub
The code works well, in that it creates a PDF, emails it to me then deletes the pdf. The problem is the PDF is of the excel worksheet not the User form I created.
What can I change to capture the form and send that via email.
Private Sub btnsendemail_Click()
Dim Mail As New Message
Dim Config As Configuration
Dim KillFile As String
Set Config = Mail.Configuration
ChDir "C:\temp"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\temp\Book1.pdf", _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
Config(cdoSendUsingMethod) = cdoSendUsingPort
Config(cdoSMTPServer) = "smtp.office365.com"
Config(cdoSMTPServerPort) = 25
Config(cdoSMTPAuthenticate) = cdoBasic
Config(cdoSMTPUseSSL) = True
Config(cdoSendUserName) = "******@******.com"
Config(cdoSendPassword) = "**********"
Config.Fields.Update
Mail.To = "******@******.com"
Mail.From = Config(cdoSendUserName)
Mail.Subject = "Email Subject"
Mail.HTMLBody = "<b>Email Body</b>"
Mail.AddAttachment "C:\temp\Book1.pdf"
On Error Resume Next
Mail.Send
If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical, "There was an error"
Exit Sub
End If
MsgBox "Your email has been sent", vbInformation, "Sent"
KillFile = "C:\temp\Book1.pdf"
'Check that file exists
If Len(Dir$(KillFile)) > 0 Then
'First remove readonly attribute, if set
SetAttr KillFile, vbNormal
'Then delete the file
Kill KillFile
End If
End Sub