earthworm
Well-known Member
- Joined
- May 19, 2009
- Messages
- 773
- Office Version
- 2019
- 2016
- Platform
- Windows
Below is the source code
Incase of any error in email address being sent to TO or CC , VBA gives an error and stopes . Some email are sent and rest are stuck .
I want to apply if error resume next so that incase of any error identified in email address go to ( run macro again for another x) . in the end i also want to find
what were the email address that had an errors on it . please guide.
VBA Code:
Sub Step5()
If Worksheets("Trigger").Range("E1").Value <> 0 Then
' To Send email along with Attachments from Folder
Dim emailApplication As Object
Dim emailItem As Object
Dim x As Integer
For x = 1 To 3
Dim nme As String
nme = Worksheets("Location").Range("A1")
Dim tomail As String
tomail = Worksheets("Brain").Range("N" & x + 1)
Dim tocc As String
tocc = "test@test.com"
Dim valuedate As String, StrPath As String, ath2 As String
valuedate = (Format(Date, "dd-mmm-yyyy"))
StrPath = (Worksheets("Location").Range("A1")) & "Outward Swift Message" & valuedate & "\"
ath = tomail & "-" & valuedate & ".pdf"
ath2 = ath
Set emailApplication = CreateObject("Outlook.Application")
Set emailItem = emailApplication.CreateItem(0)
emailItem.Body = "The message for the email."
With emailItem
.To = tomail
.CC = tocc
'.Bcc = ""
.subject = "SWIFT Message for Branch " & tomail
.HTMLBody = "Dear Branch,<br><br>Attached are the SWIFT message of your respective branch for your reference and record.<br><br>Kindly feel free to contact incase of further assistance <br><br>Regards<br>Roomi<br><Style='font-family:calibri;font-size:15'><br><span style=""color:#3366FF""><b>United Bank Limited<br>Remittance Unit</span style=""color:#3366FF""><\b>"
.Attachments.Add StrPath & ath2
'Display email before send
emailItem.Display
End With
' Send the Email
' emailItem.Send
Set emailItem = Nothing
Set emailApplication = Nothing
Next x
Else
End If
End Sub
Incase of any error in email address being sent to TO or CC , VBA gives an error and stopes . Some email are sent and rest are stuck .
I want to apply if error resume next so that incase of any error identified in email address go to ( run macro again for another x) . in the end i also want to find
what were the email address that had an errors on it . please guide.