How can i attach multiple attachments using vba code?

alang84

New Member
Joined
Oct 21, 2022
Messages
22
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi. I'm trying to automatically send an email with multiple attachments, but the email only contains the first attachment. Any idea what I'm doing wrong?


Sub EOD_No_Issues()

Application.ScreenUpdating = False

Dim MyOutlook As Object
Set MyOutlook = CreateObject("Outlook.Application")

Dim MyMail As Object
Set MyMail = MyOutlook.CreateItem(olMailItem)

MyMail.To = “email”
MyMail.CC = “”
MyMail.Subject = Range("E2").Value
MyMail.Body = "Test"

Attached_File = Range("E3").Value
Attached_File = Range("E4").Value
Attached_File = Range("E5").Value
Attached_File = Range("E6").Value
Attached_File = Range("E7").Value

MyMail.Send

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
If only 1 attachment is received you are a lucky guy, because the code doesn't include any attachment

To attach a file:
VBA Code:
MyMail.Attachments.Add NameOfFile

To attach several files, repeat the instruction several times:
VBA Code:
MyMail.Attachments.Add NameOfFile_1
MyMail.Attachments.Add NameOfFile_2
MyMail.Attachments.Add NameOfFile_3

You have to replace that "NameOfFile_x" with your name of file; I guess it will be
VBA Code:
MyMail.Attachments.Add Range("E3").Value
MyMail.Attachments.Add Range("E4").Value
'etc etc

Try...
 
Upvote 0
Solution
If only 1 attachment is received you are a lucky guy, because the code doesn't include any attachment

To attach a file:
VBA Code:
MyMail.Attachments.Add NameOfFile

To attach several files, repeat the instruction several times:
VBA Code:
MyMail.Attachments.Add NameOfFile_1
MyMail.Attachments.Add NameOfFile_2
MyMail.Attachments.Add NameOfFile_3

You have to replace that "NameOfFile_x" with your name of file; I guess it will be
VBA Code:
MyMail.Attachments.Add Range("E3").Value
MyMail.Attachments.Add Range("E4").Value
'etc etc

Try...
this worked. thanks so much. much appreciated.
 
Upvote 0
Thank you for the feedback
If that resolve the problem then it'd be better to mark the discussion as Resoved; see the procedure: Mark as Solution
 
Upvote 0

Forum statistics

Threads
1,215,646
Messages
6,126,000
Members
449,279
Latest member
Faraz5023

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top