G
Guest
i am trying to automate the sending of different attachments to a list of
recipients. So far I have the following code that will send all of the
attachments in a folder to a specified recipient:
Sub Automate()
Dim Count As Integer
Dim DirectoryFiles()
ChDir "C:\Location of files"
ffile = Dir("*.*")
Do While ffile <> ""
If ffile <> "" Then
ReDim Preserve DirectoryFiles(Count)
DirectoryFiles(Count) = ffile
Count = Count + 1
End If
ffile = Dir()
Loop
Dim objoutlook As Object
Dim objoutlookmsg As Object
Set objoutlook = CreateObject("Outlook.application")
Set objoutlookmsg = objoutlook.CreateItem(0)
With objoutlookmsg
.To = "(e-mail address removed)"
.Subject = "Test"
.Body = "Please find attached monthly reports"
'** Add all stored files**
For i = 0 To UBound(DirectoryFiles())
.Attachments.Add DirectoryFiles(i)
Next
.Send
End With
Set objoutlook = Nothing
Set objoutlookmsg = Nothing
End Sub
The issues I have now is how to alter the above to send each recipient their
correct files. For example I want cost centre manager A to receive all the
files in the folder C:\CostA while I want manager B to receive the files in
the folder C:\CostB.
Clearly this will also require different email addresses for each send also.
Any help with this would be very gratefully received.
recipients. So far I have the following code that will send all of the
attachments in a folder to a specified recipient:
Sub Automate()
Dim Count As Integer
Dim DirectoryFiles()
ChDir "C:\Location of files"
ffile = Dir("*.*")
Do While ffile <> ""
If ffile <> "" Then
ReDim Preserve DirectoryFiles(Count)
DirectoryFiles(Count) = ffile
Count = Count + 1
End If
ffile = Dir()
Loop
Dim objoutlook As Object
Dim objoutlookmsg As Object
Set objoutlook = CreateObject("Outlook.application")
Set objoutlookmsg = objoutlook.CreateItem(0)
With objoutlookmsg
.To = "(e-mail address removed)"
.Subject = "Test"
.Body = "Please find attached monthly reports"
'** Add all stored files**
For i = 0 To UBound(DirectoryFiles())
.Attachments.Add DirectoryFiles(i)
Next
.Send
End With
Set objoutlook = Nothing
Set objoutlookmsg = Nothing
End Sub
The issues I have now is how to alter the above to send each recipient their
correct files. For example I want cost centre manager A to receive all the
files in the folder C:\CostA while I want manager B to receive the files in
the folder C:\CostB.
Clearly this will also require different email addresses for each send also.
Any help with this would be very gratefully received.