Thangavel
Active Member
Hello Excel Genius,
I've code to send an excel sheet as a pdf file in outlook mail. But I need your help in modifying that code by sending multiple file in outlook based on change in a cell value (ERP_No).
Excel Version : 2016
For example, I'll updated 5 ERP_No and convert sheet1 into 5 different pdf file. After converting to 5 difference PDF file attached all those 5 in outlook mail & send.
Hope I explained my requirement clearly.
I've code to send an excel sheet as a pdf file in outlook mail. But I need your help in modifying that code by sending multiple file in outlook based on change in a cell value (ERP_No).
Excel Version : 2016
For example, I'll updated 5 ERP_No and convert sheet1 into 5 different pdf file. After converting to 5 difference PDF file attached all those 5 in outlook mail & send.
Hope I explained my requirement clearly.
Code:
Sub email_entire_Form_as_PDF()
'Create PDF of active sheet and send as attachment.
'
Dim strPath As String, strFName As String
Dim OutApp As Object, outMail As Object
Set ERP_No = Sheet1.Range("C5")
Set Booking_Ref = Sheet1.Range("G16")
'Create PDF of active sheet only
strPath = Environ$("temp") & "\" 'Or any other path, but include trailing "\"
strFName = ThisWorkbook.Name
strFName = ERP_No.Value & "_" & Booking_Ref.Value & "_" & ActiveSheet.Name & ".pdf"
Sheet1.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
strPath & strFName, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
'Set up outlook
Set OutApp = CreateObject("Outlook.Application")
Set outMail = OutApp.CreateItem(0)
'Create message
On Error Resume Next
With outMail
.to = "" 'Insert TA email id########
.CC = ""
.BCC = ""
.Subject = "tybe subject here.."
.Body = "Type the body of the mail here..." & vbCr & "Best regards," & vbCr & "Team" & vbCr
.Attachments.Add strPath & strFName
'.Display 'Use only during debugging ##############################
.send 'Uncomment to send e-mail ##############################
End With
'Delete any temp files created
Kill strPath & strFName
On Error GoTo 0
MsgBox "PDF file of this form sent ...", vbInformation, "Information"
Set outMail = Nothing
Set OutApp = Nothing
End Sub