Send email multiple attachments

Farrp001

New Member
Joined
Nov 17, 2020
Messages
12
Office Version
  1. 2019
Platform
  1. Windows
I am using the below Sub script as part of the a script that creates a PDF from Excel and attaches that PDF to an email via outlook and sends out the email via Outlook. What I was looking to do is add another attachment (already created and saved word doc) to that email, so that when the script creates the PDF and attaches it to an outgoing email it will also add a copy of the word doc.

Any help is appreciated

Public Sub Send_Email(toEmail As String, fileAttachment As String)

Static olApp As Object
Dim olMsg As Object

If olApp Is Nothing Then Set olApp = CreateObject("Outlook.Application")

Set olMsg = olApp.CreateItem(0)
With olMsg
.To = toEmail
.CC = "myeamil.com"
.Subject = "On-boarding Process"
.HTMLBody = " Please review the attached form (those with existing... accounts will need to be updated..."
.Attachments.Add fileAttachment
.Send
End With

End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Simplest way:
VBA Code:
Public Sub Send_Email(toEmail As String, fileAttachment1 As String, fileAttachment2 As String)
then inside:
VBA Code:
.Attachments.Add fileAttachment1
.Attachments.Add fileAttachment2
 
Upvote 0
Simplest way:
VBA Code:
Public Sub Send_Email(toEmail As String, fileAttachment1 As String, fileAttachment2 As String)
then inside:
VBA Code:
.Attachments.Add fileAttachment1
.Attachments.Add fileAttachment2
Thank you much for the reply... Excuse my ingnorance, I know just enough to f... Things Up... How to I point the saved Word.Docx to fileAttachemnt2 or vise versa
 
Upvote 0
Sub SendEmailWith2Attachments()
Call (Send_Email ("addressX@somewhere.com", "C:\users\Anonymous\report.pdf", "C:\users\Anonymous\AlreadyCreatedWordDocument.Docx")
End Sub
 
Upvote 0
VBA Code:
fileAttahcment2 = C:\Users\Desktop\Work\script\Test.docx
 
Upvote 0
Sub SendEmailWith2Attachments()
Call (Send_Email ("addressX@somewhere.com", "C:\users\Anonymous\report.pdf", "C:\users\Anonymous\AlreadyCreatedWordDocument.Docx")
End Sub
That is in addition to the last reply so you get this?

VBA Code:
Public Sub Send_Email(toEmail As String, fileAttachment1 As String, fileAttachment2 As String)
[I]
Static olApp As Object
Dim olMsg As Object

If olApp Is Nothing Then Set olApp = CreateObject("Outlook.Application")

Set olMsg = olApp.CreateItem(0)
With olMsg
.To = toEmail
.CC = "myeamil.com"
.Subject = "On-boarding Process"
.HTMLBody = " Please review the attached form (those with existing... accounts will need to be updated..."
.Attachments.Add fileAttachment1
[I].Attachments.Add fileAttachment2[/I]
.Send
End With

End Sub[/I]

Sub SendEmailWith2Attachments()
Call (Send_Email ("[EMAIL]addressX@somewhere.com[/EMAIL]", "C:\users\Anonymous\report.pdf", "C:\users\Anonymous\AlreadyCreatedWordDocument.Docx")
End Sub
 
Upvote 0
Delete tags from vba code.

VBA Code:
Public Sub Send_Email(toEmail As String, fileAttachment1 As String, fileAttachment2 As String)
Static olApp As Object
Dim olMsg As Object

If olApp Is Nothing Then Set olApp = CreateObject("Outlook.Application")

Set olMsg = olApp.CreateItem(0)
With olMsg
.To = toEmail
.CC = "myeamil.com"
.Subject = "On-boarding Process"
.HTMLBody = " Please review the attached form (those with existing... accounts will need to be updated..."
.Attachments.Add fileAttachment1
[I].Attachments.Add fileAttachment2[/I]
.Send
End With

End Sub

Sub SendEmailWith2Attachments()
Call (Send_Email ("addressX@somewhere.com", "C:\users\Anonymous\report.pdf", "C:\users\Anonymous\AlreadyCreatedWordDocument.Docx")
End Sub
 
Upvote 0
Thank you for coming back to me on this Kokosak

I am probably missing the obvious but here is where I am and I am receiveing Compile Error "Argument is not optional" prior to i in script, this is where it is grabbing pdf from for attachemnt1

VBA Code:
 End If
   
    Send_Email shWrite.Cells(i, 3).Value, strPDFOutPath
   
    Next i


Here is what I am using

VBA Code:
Public Sub Send_Email(toEmail As String, fileAttachment1 As String, fileAttachment2 As String)

    Static olApp As Object
    Dim olMsg As Object
 
    If olApp Is Nothing Then Set olApp = CreateObject("Outlook.Application")
 
    Set olMsg = olApp.CreateItem(0)
    With olMsg
        .To = toEmail
        .CC = "mymail.com"
        .Subject = "On-boarding Process"
        .HTMLBody = "Main body text here
        .Attachments.Add fileAttachment1
        .Attachments.Add fileAttachment2
        .Send
    End With
     
End Sub

Sub SendEmailWith2Attachments()
Call Send_Email("addressX@somewhere.com", "c:\user\anonymous\report.pdf", "C:\Users\farellp\Desktop\Working Email Version Cheshire\Test.docx")
End Sub
 
Last edited:
Upvote 0
Because this sub needs 2 parameters

VBA Code:
Public Sub Send_Email(toEmail As String, fileAttachment1 As String, fileAttachment2 As String)

try to change it into

VBA Code:
Public Sub Send_Email(toEmail As String, optional fileAttachment1 As String, optional fileAttachment2 As String)
so as 2nd and 3rd parameter are optional you do not have to set them (but You can)
and there something like (to check that optional 1 and optional2 has been put)

VBA Code:
if  fileAttachment1 then .Attachments.Add fileAttachment1
if  fileAttachment2 then .Attachments.Add fileAttachment2
 
Upvote 0
Solution

Forum statistics

Threads
1,214,522
Messages
6,120,019
Members
448,938
Latest member
Aaliya13

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