I have a very simple code that I have created in outlook where the code will pick up an email template that was created, open it and add files to the email. I have the designated path for vba to pick and choose the file. My current problem is that sometimes the file in that path/folder may not be available one month but it will be the next. I have searched for hours on how to have the vba attach the first file, and skip the second file if it is not available this month, and go to the next line of code and attach any remaning file that matches the exact file name.
example
file1.xlsx is available this month so vba attaches to the email
file2.xlsx is not available this month so it goes to the next line of code/file and attaches to the email
file3.xlsx attached to email
file4.xlsx attached to email
The end result that files 1,3 & 4 would be attached and any errors from not finding file2 would be eliminated while the available files are attached.
Thank you in advance for any help!
My code is below.
Sub email()
Set newItem = Application.CreateItemFromTemplate("H:\Documents\Custom Office Templates\Outlook\Email file.oft")
newItem.Display
newItem.Attachments.Add "c:\file1.xlsx"
newItem.Attachments.Add "c:\file2.xlsx"
newItem.Attachments.Add "c:\file3.xlsx
newItem.Attachments.Add "c:\file4.xlsx
End Sub
example
file1.xlsx is available this month so vba attaches to the email
file2.xlsx is not available this month so it goes to the next line of code/file and attaches to the email
file3.xlsx attached to email
file4.xlsx attached to email
The end result that files 1,3 & 4 would be attached and any errors from not finding file2 would be eliminated while the available files are attached.
Thank you in advance for any help!
My code is below.
Sub email()
Set newItem = Application.CreateItemFromTemplate("H:\Documents\Custom Office Templates\Outlook\Email file.oft")
newItem.Display
newItem.Attachments.Add "c:\file1.xlsx"
newItem.Attachments.Add "c:\file2.xlsx"
newItem.Attachments.Add "c:\file3.xlsx
newItem.Attachments.Add "c:\file4.xlsx
End Sub