Sub ComName_Click()
Dim objOL As Object
Dim objMail As Object
On Error GoTo 1
Set objOL = CreateObject("Outlook.Application")
Set objMail = objOL.CreateItem(0)
With objMail
.To = [b3]
.CC = [c3]
.Body = [e3]
.Subject = [d3] & " " & [h1]
.Attachments.Add "C:\Users\File1.xlsx"
.Attachments.Add "C:\Users\File2.xlsx"
.display
End With
Exit Sub
1:
Set objOL = CreateObject("Outlook.Application")
Set objMail = objOL.CreateItem(0)
With objMail
.To = [b3]
.CC = [c3]
.Body = [e3]
.Subject = [d3] & " " & [h1]
.display
End With
End Sub
Sometimes files are absent and I need create the letter without attachments. - Can I make the "1" part of code shorter? - How can I upgrade the code in case if one of files "File1" or "File2" is absent, and system should attach only one of them which is available?
Thanks in advance