Carl Stephens
New Member
- Joined
- Jan 3, 2017
- Messages
- 46
- Office Version
- 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
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