whoosh 03:28 AM Today
Hi,
I am not very good at coding, trying to get the following code to work.
Intention is to mass send Outlook emails with PDF attachment (name =subject header) from excel list.
Example
Subject Header = 3127: Hundred Palms - To remove debris, $15000
PDF file to attach = 3127 Hundred Palms - To remove debris, $15000
I face problem when there is a new revision to the same quote - from Q23/3127 to Q23/3127a.
The PDF file cannot be recognised and be attached to Outlook.
I would like to email and attach the latest revision only. Would appreciate if anyone can help.
Thanks in advance.
Hi,
I am not very good at coding, trying to get the following code to work.
Intention is to mass send Outlook emails with PDF attachment (name =subject header) from excel list.
Example
Subject Header = 3127: Hundred Palms - To remove debris, $15000
PDF file to attach = 3127 Hundred Palms - To remove debris, $15000
VBA Code:
Sub Send_Email_From_Excel()
Dim emailApp As Object
Set emailApp = CreateObject("Outlook.Application")
Dim emailItem As Object
Path = "D:\My Files\"
QuoteNo = Range("D7")
Descrip = Range("G7")
Amount = Range("K7")
'fname = Descrip
Dim mail_list As Range
Dim cell As Range
Application.ScreenUpdating = False
On Error GoTo error_exit
Set mail_list = Range(Range("O7"), Range("O7").End(xlDown))
For Each cell In mail_list
Set emailItem = emailApp.CreateItem(0)
On Error Resume Next
With emailItem
.To = cell.Value
'.cc = "sales@xxx.com"
.Subject = Cells(cell.Row, "D").Value & ": " & Cells(cell.Row, "G").Value & ", " & "$" & Cells(cell.Row, "K").Value
'.Subject = "Q23/" & Cells(cell.Row, "D").Value & ": " & Cells(cell.Row, "G").Value & ", " & "$" & Cells(cell.Row, "K").Value
.Attachments.Add (Path & Cells(cell.Row, "D").Value & " " & Cells(cell.Row, "G").Value & ", " & "$" & Cells(cell.Row, "K").Value & ".pdf")
.Body = "Dear " & Cells(cell.Row, "J").Value & "," & vbNewLine & vbNewLine & _
"A gentle reminder for an update on the subjected mentioned" & vbNewLine & _
"Feel free to contact us if you have any enquiries" & vbNewLine & vbNewLine & _
"Thanks and best regards" & "," & vbNewLine & _
"Yan"
'Diplay the email so user can change it as desired before sending it.
.Display
'Save the email in the draft folder.
'.Save
'Send Email
'.Send
End With
On Error GoTo 0
Set emailItem = Nothing
Next cell
error_exit:
Set emailApp = Nothing
Application.ScreenUpdating = True
End Sub
Sub Remove_Q23_from_QuoteNo()
With Range("D7", Range("D" & Rows.Count).End(xlDown))
.Replace What:="Q23/", Replacement:="", LookAt:=xlPart
End With
End Sub
I face problem when there is a new revision to the same quote - from Q23/3127 to Q23/3127a.
The PDF file cannot be recognised and be attached to Outlook.
I would like to email and attach the latest revision only. Would appreciate if anyone can help.
Thanks in advance.