Greetings
I have a MACRO I'm working on that is supposed to convert specific sheets in a workbook to a PDF file and attach the PDF in an outlook mail to send out to managers. The sample code is below. I'm able to create the PDF file with no issue but the MACRO can't find the same file path and name used in order to attach to the email. Can anyone help me?
>>> use code - tags <<<
I have a MACRO I'm working on that is supposed to convert specific sheets in a workbook to a PDF file and attach the PDF in an outlook mail to send out to managers. The sample code is below. I'm able to create the PDF file with no issue but the MACRO can't find the same file path and name used in order to attach to the email. Can anyone help me?
>>> use code - tags <<<
Code:
Sub SendPrelimTest()
Dim answer As VbMsgBoxResult
Dim FilePath As String
Dim PrelimName As String
Dim BaseFileName As String
Dim FileNameArray() As String
Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim myAttachment As Object
Dim SendTo As Variant
Dim AttachmentPath As String
Set OutLookApp = CreateObject("Outlook.Application")
Set OutLookMailItem = OutLookApp.CreateItem(0)
Set myAttachment = OutLookMailItem.Attachments
answer = MsgBox("Are you ready to send preliminary report?", vbYesNo + vbQuestion)
If answer = vbYes Then
ThisWorkbook.Save
FilePath = ThisWorkbook.Path & "\"
FileNameArray = Split(ThisWorkbook.Name, ".")
BaseFileName = FileNameArray(0)
PrelimName = "Preliminary " & BaseFileName
AttachmentPath = FilePath & PrelimName
Sheets(Array("Break Even", "Summary - Preliminary")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=AttachmentPath, _
IncludeDocProperties:=False
MsgBox "PDF file has been created: " & AttachmentPath & vbNewLine _
& "Please look over File and make changes if needed."
Range("E43").Select
Else
ThisWorkbook.Save
Range("E43").Select
End If
Sheets("Analyst Use").Select
SendTo = ActiveSheet.Range("D1").Value
With OutLookMailItem
.To = SendTo
.Subject = PrelimName
myAttachment.Add AttachmentPath
.Display
End With
Set OutLookMailItem = Nothing
Set OutLookApp = Nothing
Sheets(4).Select
End Sub
Last edited by a moderator: