Use VBA to attach document from referenced cell to email through Outlook

VBANEWBIE1229

New Member
Joined
Oct 19, 2017
Messages
5
Hi guys, I am trying to send an email automatically from excel 2013 using VBA, the email is successful, however, I am having trouble getting it to attach a document from a referenced cell. I would like it to attach the document that is linked into cell B9. The following code is what I have. Thanks in advance for your help!!!
Rich (BB code):
Private Sub CommandButton21_Click()
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
Set Rng = Range("B9")
On Error Resume Next
With OutMail
.To = Range("D9")
.CC = Range("E9")
.BCC = ""
.Subject = "Subject"
.Body = "Body"
.Attachments.Add ActiveSheet.Range("b9").Select
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 
Last edited by a moderator:

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Untested but you could try replacing

Code:
[B][U].Attachments.Add ActiveSheet.Range("b9").Select[/U][/B]

With

Code:
[COLOR=#303336][FONT=inherit].[/FONT][/COLOR][COLOR=#303336][FONT=inherit]Attachments[/FONT][/COLOR][COLOR=#303336][FONT=inherit].[/FONT][/COLOR][COLOR=#303336][FONT=inherit]Add [/FONT][/COLOR][COLOR=#303336][FONT=inherit]([/FONT][/COLOR][COLOR=#303336][FONT=inherit]ActiveSheet.Range("B9").Value[/FONT][/COLOR][COLOR=#303336][FONT=inherit])[/FONT][/COLOR]

This Should work as long as B9 contains the full path of the file
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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