Please help with a following code. Something wrong , but I can't find an error. Code taking the name from "model" column in Excel, adding to it extention "doc" and looking it in SourcePath folder. After that it is adding to an email.
I need to add to each message all attachents where the same name in "supplier" coulmn.
From example file: email to Gold will sent with two attachments (polo.doc and bora.doc), while email to Toyota will sent one attachment only (yaris.doc).
Sub SendMultEmails() Dim olApp As Outlook.Application Dim objOutlookAttach As Outlook.Attachments Dim olMail As MailItem Dim ext As String Dim i As Integer Set olApp = New Outlook.Application ' template of MS Outlook ChDrive "C:" ChDir "C:\Documents and Settings\user\Application Data\Microsoft\Templates" TemplateFile = Application.GetOpenFilename(Title:="Select the template") SourcePath = GetFolderPath & "\" ext = InputBox("What extention of file to search (doc/xls/pdf..) ?") Set olMail = olApp.CreateItemFromTemplate(TemplateFile) Range("a2").Select Range(Selection, Selection.End(xlDown)).Select temp = "" For Each rng In Selection SourceFile = SourcePath & rng.Offset(0, 1) & "." & ext Set olMail = olApp.CreateItemFromTemplate(TemplateFile) With olMail .To = rng.Offset(0, 5) .HTMLBody = "<font face='Arial' color= Navy size=2>" & "Hi " & rng.Offset(0, 3) & "," & "</font>" & .HTMLBody i = -1 Set objOutlookAttach = olMail.Attachments Do temp = rng.Value SourceFile = SourcePath & rng.Offset(0, 1) & "." & ext objOutlookAttach.Add (SourceFile) i = i + 1 Loop Until rng.Offset(i + 1, 0) <> temp .Display .send End With temp = rng.Value Set olMail = Nothing Next rng end sub