I have some code that finds pdf's and excel files.
Currently the code will find
Smith, John (Feb-15) - Managed .pdf
Smith, John (Feb-15) - Booked .pdf
etc etc
My file names now have an extra component and they will be either
Smith, John - GB-CORP (Feb-15) - Managed .pdf or
Smith, John - GB-FI (Feb-15) - Managed .pdf or
Smith, John - CMB-LC (Feb-15) - Managed .pdf or
Smith, John - CMB-MME (Feb-15) - Managed .pdf or
How can I factor in these new additions to the file name into the below code?
Thanks!
Sub send_email(str As String, str1 As String)'Dim MailDbName As StringDim Recipient As VariantDim ccRecipient As StringDim Attachment1 As StringDim Attachment2 As StringDim Attachment3 As StringDim Attachment4 As StringDim Attachment5 As StringDim Maildb As ObjectDim MailDoc As ObjectDim AttachME As ObjectDim AttachME2 As ObjectDim AttachME3 As ObjectDim AttachME4 As ObjectDim AttachME5 As ObjectDim Session As ObjectDim EmbedObj1 As ObjectDim EmbedObj2 As ObjectDim EmbedObj3 As ObjectDim EmbedObj4 As ObjectDim EmbedObj5 As ObjectDim stSignature As StringWith Application.ScreenUpdating = False.DisplayAlerts = False' Open and locate current LOTUS NOTES UserSet Session = CreateObject("Notes.NotesSession")UserName = Session.UserNameSet Maildb = Session.GetDatabase("", MailDbName)If Maildb.IsOpen = True ThenElseMaildb.OPENMAILEnd If' Create New Mail and Address Title HandlersSet MailDoc = Maildb.CREATEDOCUMENTMailDoc.Form = "Memo"' Select range of e-mail addressesRecipient = Array(str1)MailDoc.Principal = Range("R5").ValueMailDoc.SendTo = RecipientMailDoc.Subject = "Sales Manager Horis Report Feb 2015"Set mailbody = MailDoc.CreateRichTextItem("Body")Call mailbody.AppendText("Please find attached your Sales Manager Horis Reports for February 2015. ")Call mailbody.Addnewline(1)Call mailbody.Addnewline(1)Call mailbody.AppendText("If you have any questions around the content of these reports, please contact your Regional SPM team in the first instance. ")Call mailbody.Addnewline(1)Call mailbody.Addnewline(1)Call mailbody.AppendText("A guide to reading the Sales Dashboard can be found in the following link:")Call mailbody.Addnewline(1)Call mailbody.Addnewline(1)Call mailbody.AppendText("")Call mailbody.Addnewline(1)Call mailbody.Addnewline(1)Call mailbody.AppendText("If you have received this email in error, please delete and contact the regional mailbox in order for you to be removed from future monthly automated mailings.")Call mailbody.Addnewline(2)' Select Workbook to Attach to E-MailDim stfilename1 As String, stfilename2 As String, stfilename3 As StringDim stpath As Stringstpath = "R:\SPM\Horis Info\Horis_Project\GBM\" & Format(Cells(5, 15).Value, "mmm-yy") & "\Output\" & Cells(5, 13).Value & "\All" stfilename1 = str & " (" & Format(Cells(5, 15).Value, "mmm-yy") & ") - Managed .pdf" stfilename2 = str & " (" & Format(Cells(5, 15).Value, "mmm-yy") & ") - Booked .pdf" stfilename3 = str & " (" & Format(Cells(5, 15).Value, "mmm-yy") & ") - Booked Region .pdf" stfilename4 = str & " (" & Format(Cells(5, 15).Value, "mmm-yy") & ") - Managed.xlsx" stfilename5 = str & " (" & Format(Cells(5, 15).Value, "mmm-yy") & ") - Booked.xls" stfilename6 = str & " (" & Format(Cells(5, 15).Value, "mmm-yy") & ") - Booked Region.xlsx"MailDoc.SaveMessageOnSend = TrueAttachment1 = stpath & "\" & stfilename1If Attachment1 <> "" ThenOn Error Resume NextSet AttachME = MailDoc.CreateRichTextItem("attachment1")Set EmbedObj1 = AttachME.EmbedObject(1454, "attachment1", Attachment1, "") 'Required File NameOn Error Resume NextEnd IfAttachment2 = stpath & "\" & stfilename2 '"C:\YourFile.xls" ' Required File NameIf Attachment2 <> 0 ThenOn Error Resume NextSet AttachME2 = MailDoc.CreateRichTextItem("attachment2")Set EmbedObj2 = AttachME.EmbedObject(1454, "attachment2", Attachment2, "") 'Required File NameOn Error Resume NextEnd IfAttachment3 = stpath & "\" & stfilename3 '"C:\YourFile.xls" ' Required File NameIf Attachment3 <> "" ThenOn Error Resume NextSet AttachME3 = MailDoc.CreateRichTextItem("attachment3")Set EmbedObj3 = AttachME.EmbedObject(1454, "attachment3", Attachment3, "") 'Required File NameOn Error Resume NextEnd IfAttachment4 = stpath & "\" & stfilename4 '"C:\YourFile.xls" ' Required File NameIf Attachment4 <> "" ThenOn Error Resume NextSet AttachME = MailDoc.CreateRichTextItem("attachment4")Set EmbedObj4 = AttachME.EmbedObject(1454, "attachment4", Attachment4, "") 'Required File NameOn Error Resume NextEnd IfAttachment5 = stpath & "\" & stfilename5 '"C:\YourFile.xls" ' Required File NameIf Attachment5 <> 0 ThenOn Error Resume NextSet AttachME5 = MailDoc.CreateRichTextItem("attachment5")Set EmbedObj5 = AttachME.EmbedObject(1454, "attachment5", Attachment5, "") 'Required File NameOn Error Resume NextEnd IfAttachment6 = stpath & "\" & stfilename6 '"C:\YourFile.xls" ' Required File NameIf Attachment6 <> "" ThenOn Error Resume NextSet AttachME6 = MailDoc.CreateRichTextItem("attachment6")Set EmbedObj6 = AttachME.EmbedObject(1454, "attachment6", Attachment6, "") 'Required File NameOn Error Resume NextEnd If If Dir(Attachment1) <> "" Or Dir(Attachment2) <> "" Or Dir(Attachment3) <> "" Or Dir(Attachment4) <> "" Or Dir(Attachment5) <> "" Or Dir(Attachment6) <> "" Then MailDoc.PostedDate = Now() On Error GoTo errorhandler1 MailDoc.SEND 0, Recipient Else Cells(cell.Row, "t").Value = "Email attachment is missing for this name" End IfSet Maildb = NothingSet MailDoc = NothingSet AttachME = NothingSet AttachME2 = NothingSet AttachME3 = NothingSet AttachME4 = NothingSet AttachME5 = NothingSet Session = NothingSet EmbedObj1 = NothingSet EmbedObj2 = NothingSet EmbedObj3 = NothingSet EmbedObj4 = NothingSet EmbedObj5 = Nothing.ScreenUpdating = True.DisplayAlerts = TrueEnd Witherrorhandler1:Set Maildb = NothingSet MailDoc = NothingSet AttachME = NothingSet AttachME2 = NothingSet AttachME3 = NothingSet AttachME4 = NothingSet AttachME5 = NothingSet Session = NothingSet EmbedObj1 = NothingSet EmbedObj2 = NothingSet EmbedObj3 = NothingSet EmbedObj4 = NothingSet EmbedObj5 = NothingEnd Sub