Hello there!
I'm trying to modify an old macro I used from before but this time rather than just sending emails based on cell values and adding just one specific attachment, I'm needing it to add a different attachment to each of the emails. The code that I tried to modify just keeps giving me there error "Cannot find this file. Verify the path and file name are correct.". I know the path is correct so I'm assuming the issue is my method here... I'm not all that great in VBA... just dangerous enough to make things work occasionally. Here's what I have so far... any help would be greatly appreciated!:
I'm trying to modify an old macro I used from before but this time rather than just sending emails based on cell values and adding just one specific attachment, I'm needing it to add a different attachment to each of the emails. The code that I tried to modify just keeps giving me there error "Cannot find this file. Verify the path and file name are correct.". I know the path is correct so I'm assuming the issue is my method here... I'm not all that great in VBA... just dangerous enough to make things work occasionally. Here's what I have so far... any help would be greatly appreciated!:
Code:
<code>
Sub Send_Commission_Letter()
Dim SendTo As String
Dim SendCC As String
Dim ToMSg As String
Dim AddAttachment As String
For i = 1 To 100
SendTo = ThisWorkbook.Sheets(1).Cells(i, 3)
SendCC = ThisWorkbook.Sheets(1).Cells(i, 5)
AddAttachment = ThisWorkbook.Sheets(1).Cells(i, 6).Value
If SendTo <> "" Then
ToMSg = ThisWorkbook.Sheets(1).Cells(i, 7)
Send_Commission_email SendTo, SendCC, AddAttachment, ToMSg
End If
Next i
End Sub
Sub Send_Commission_email(SendTo As String, SendCC As String, AddAttachment As String, ToMSg As String)
Sheets("SendMail").Select
Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim MyPath As String
MyPath = "C:\Users\Me\Desktop\filename.pdf" 'location of picture to be attached
Set olApp = CreateObject("Outlook.Application") 'reference to Outlook
Set olMail = olApp.CreateItem(olMailItem) 'reference to new email
With olMail
.To = SendTo
.CC = SendCC
.Subject = Range("B3").Value
.Body = ToMSg
.Attachments.Add AddAttachment
'.Attachments.Add MyPath
.Display
.Send
End With
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End Sub
</code>
Last edited by a moderator: