VBA - Code to Add PDF attachment to Automated Email

PHayes35

New Member
Joined
Dec 6, 2017
Messages
6
Hey Guys, I currently have code that creates a Term Sheet from multiple Excel Pages and saves it in a specific folder. I'm looking to write code that sends an email with the term sheet I saved as an attachment. Below is the code I have: (Range B5 is file location and Range B4 is the file name - this is the line of code receiving errors.) The email itself works fine, just the attachment. Thanks for any help!

Code:
Sheets("Company Email").Select


    Dim objOutlook As Object
    Dim objMail As Object
    Dim Content As Range
    Dim SendTo As String
    Dim CC As String
    Dim subject As String
    Dim RowCC As Integer
    Dim RowTo As Integer


    Dim RowSubject As Integer
    
    RowTo = WorksheetFunction.Match("TO:", Range("A1:A500"), 0)
    RowCC = WorksheetFunction.Match("CC:", Range("A1:A500"), 0)
    RowSubject = WorksheetFunction.Match("Subject:", Range("A1:A500"), 0)
    Set Content = Range("B9:F9")
    SendTo = Range("B" & RowTo)
    CC = Range("B" & RowCC)
    subject = Range("B" & RowSubject)
    Content.Select
    Selection.Copy
    
    'send email
    Set objOutlook = CreateObject("Outlook.Application")
    Set objMail = objOutlook.CreateItem(0)






    With objMail


        .To = SendTo
        .subject = subject
        .CC = CC
        .Display
        .Attachments.Add Range("B5").Value & "\" & Range("B4").Value & ".pdf"


        
    End With
    
     Set wEditor = objOutlook.ActiveInspector.WordEditor
     wEditor.Application.Selection.Paste
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I actually solved it, but thanks for the response. The issued lied in the code that created the PDF - did not include the address of the file in the file name.
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,834
Members
449,471
Latest member
lachbee

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