PDA

View Full Version : [SOLVED] Send all files in folder vba



greyangel
02-13-2018, 01:32 PM
I am currently using the code attached to send a single file path. Would somebody be able to help me modify the code to send all files in a particular folder instead of just 1 file?

mancubus
02-14-2018, 02:10 AM
?



Sub vbax_61999_email_all_files_in_folder()

Dim strFolder As String
Dim fso As Object
Dim fsoFolder As Object
Dim fsoFile As Object

Set fso = CreateObject("Scripting.FileSystemObject")

With CreateObject("Outlook.Application")
For i = 2 To Cells(Rows.Count, 2).End(xlUp).Row
strFolder = Range("C" & i).Value
If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"
Set fsoFolder = fso.GetFolder(strFolder)
With .CreateItem(olMailItem)
.To = Range("B" & i).Value
.Subject = Range("I2").Value
.Body = Range("J2").Value
For Each fsoFile In fsoFolder.Files
.Attachments.Add strFolder & fsoFile.Name
Next
.Display 'or 'Send
End With
Range("F" & i).Value = Format(Date, "mm/dd/yy")
Next
End With

End Sub

greyangel
02-16-2018, 07:12 AM
Thank you for the help.