hi all
I have the below code which inserts the active sheet as a pdf in an outlook email attachment
I would like to add one thing to this code, that if I already have an outlook email open with another pdf it should add the next active open pdf excel file to the original outlook item instead of creating a new outlook email also, I want to add to the subject the additional new file its adding.
Any help is greatly appreciated.
I have the below code which inserts the active sheet as a pdf in an outlook email attachment
VBA Code:
Sub Email_ActiveSheet_As_PDF5211111()
Dim OlApp As Object
Dim NewMail As Object
Dim TempFilePath As String
Dim strbody As String
Dim signature As String
Dim TempFileName As String
Dim FileFullPath As String
Dim bb As String
Dim Ext As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
If Worksheets("rrInvoice").Range("H4") = "" And Worksheets("rrInvoice").Range("G1") = "Invoice" Then
bb = "Order #" & " " & Worksheets("rrInvoice").Range("G8")
ElseIf Worksheets("rrInvoice").Range("H4") <> "" And Worksheets("rrInvoice").Range("G1") = "Invoice" Then
bb = "Invoice #" & " " & Worksheets("rrInvoice").Range("H4")
ElseIf Worksheets("rrInvoice").Range("H4") <> "" And Worksheets("rrInvoice").Range("G1") = "Credit" Then
bb = "Credit #" & " " & Worksheets("rrInvoice").Range("H4")
End If
If Application.UserName = "jack" Then
Ext = "0"
End If
TempFilePath = Environ$("temp") & "\"
TempFileName = bb & ".pdf"
FileFullPath = TempFilePath & TempFileName
On Error GoTo err
With ActiveSheet
.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=FileFullPath, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End With
Set OlApp = CreateObject("Outlook.Application")
Set NewMail = OlApp.CreateItem(0)
On Error Resume Next
With NewMail
.Display
End With
signature = NewMail.HTMLBody
If Worksheets("rrInvoice").Range("H4") = "" And Worksheets("rrInvoice").Range("G1") = "Invoice" Then
strbody = "<BODY style=font-size:12pt;font-family:Calibri>" & _
"Please see the attached order." & "</b> " & "<br><br>" & _
"Any questions or concerns please feel free to contact me at 000-000-0000." & " " & "Ext." & " " & Ext & "</b> " & "<br><br>" & _
"Thank you for your business."
ElseIf Worksheets("rrInvoice").Range("H4") <> "" And Worksheets("rrInvoice").Range("G1") = "Invoice" Then
strbody = "<BODY style=font-size:12pt;font-family:Calibri>" & _
"Please see the attached invoice." & "</b> " & "<br><br>" & _
"Any questions or concerns please feel free to contact me at 000-000-0000." & " " & "Ext." & " " & Ext & "</b> " & "<br><br>" & _
"Thank you for your business."
ElseIf Worksheets("rrInvoice").Range("H4") <> "" And Worksheets("rrInvoice").Range("G1") = "Credit" Then
strbody = "<BODY style=font-size:12pt;font-family:Calibri>" & _
"Please see the attached Credit." & "</b> " & "<br><br>" & _
"Any questions or concerns please feel free to contact me at 000-000-0000." & " " & "Ext." & " " & Ext & "</b> " & "<br><br>" & _
"Thank you for your business."
End If
With NewMail
.To = ""
.CC = ""
.Subject = bb
.HTMLBody = strbody & signature
.Attachments.Add FileFullPath
.Display.To
End With
On Error GoTo 0
Kill FileFullPath
Set NewMail = Nothing
Set OlApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Exit Sub
err:
MsgBox err.Description
End Sub
I would like to add one thing to this code, that if I already have an outlook email open with another pdf it should add the next active open pdf excel file to the original outlook item instead of creating a new outlook email also, I want to add to the subject the additional new file its adding.
Any help is greatly appreciated.