Skip if error

Carl Stephens

New Member
Joined
Jan 3, 2017
Messages
46
Office Version
  1. 365
Hello All,

I have the below code where an email is created in Outlook and it searches for the required attachments based on a IF condition is met, and if the IF is condition is not met and the formula returns a blank, what needs to go in the code to skip and move to the next attachment, as the below code currently stops all TRUE attachments from loading if just one returns a FALSE?

Sub One()

Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Dim ws As Worksheet
Dim strSignature As String '< new string variable

Set ws = Sheets("1E")
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
MsgBox "Don't forget to assign a Marlin's code if required!. Close the email and enter the Marlins code on the MC tab if you have forgotten, then press the email button again."

With xOutMail
.Display
.To = ws.Range("C2").Value
.CC = ws.Range("C3").Value
.BCC = ws.Range("C4").Value
.Subject = ws.Range("C5").Value
strSignature = .HTMLBody 'the signature is there, so get it before overwriting the body
.HTMLBody = Join(Application.Transpose(ws.Range("C14", ws.Cells(ws.Rows.Count, "C").End(xlUp)).Value), vbVerticalTab) & vbCrLf & strSignature '< concatenate the signature to the end
On Error Resume Next
.Attachments.Add ws.Range("C6").Value
.Attachments.Add ws.Range("C7").Value
.Attachments.Add ws.Range("C8").Value
.Attachments.Add ws.Range("C9").Value
.Attachments.Add ws.Range("C10").Value
.Attachments.Add ws.Range("C11").Value
.Attachments.Add ws.Range("C12").Value

On Error GoTo 0
End With

On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
it searches for the required attachments based on a IF condition is met, and if the IF is condition is not met and the formula returns a blank
I am not following this. There is no If statement anywhere in this code.
 
Upvote 0
I am not following this. There is no If statement anywhere in this code.
The IF statement is a formula in a cell......it states "If cell is equal to British, then add this attachment" and the attachment works, however, if it not British, then it does not attach the file but it stops the next files in the code from being added.
 
Upvote 0
What cell, and what is the formula?

Your On Error Resume Next should be causing all the attachments to be added even if one fails.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,279
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top