Trying to attach pdf to an email with VBA

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
563
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
On my spreadsheet I have a invoice template with an activex button. When that button is clicked it converts spreadsheet to a pdf and saves it to a designated location and attaches it to an email to be sent. Everything works except the attaching it to an email. My laptop has Office 365 built into it but the trial expired on it, so I installed my older version of Office 2010 since I already had the product key for it.

I created a module called Public_Variables and in that module I have a variable called
Code:
Public sPathSaved As String
Below is the rest of the code used.
VBA Code:
Private Sub btnSave_Email_Click()
    Dim sPath As String
    Dim sFilename As String
    
    'sPath = "C:\Users\username\Desktop\Saved PDF TEST\"
    sPath = "C:\Users\username\Desktop\Saved PDF Test\"
    sFilename = Range("A7").Text
    ActiveSheet.ExportAsFixedFormat xlTypePDF, sPath & sFilename
    sPathSaved = sPath & sFilename & ".pdf"
    Call send_Email
    
End Sub
I'm getting the error of Run-Time Error '287: Application-defined or object-defined error from the below sub on this line
Code:
    Set OutMail = OutApp.CreateItem(olMailItem)
Code:
Sub send_Email()

    Dim OutApp As Outlook.Application
    Dim OutMail As Outlook.MailItem
    
    Set OutApp = New Outlook.Application
    Set OutMail = OutApp.CreateItem(olMailItem)

        With OutMail
            .attachments.Add "C:\Users\Jacob B Cutler\Desktop\Saved PDF TEST\"
        End With
    
End Sub

Thank You
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
After I uncheck Microsoft Outlook 16.0 Object Library, I'm still getting Run-Time error '287: Application-defined or object difined error.
VBA Code:
Set OutLookMailItem = OutLookApp.CreateItem(0)
 
Upvote 0
Capture.PNG

Here is what is checked and I am still getting that same Runt-time error.
 
Upvote 0
The only other thing I can think of is that it's down to security policies.
Either something is blocking other apps from sending emails, or maybe outlook cannot find any antivirus software, or thinks it's out of date.
 
Upvote 0
Probably, but as I don't use outlook, I've no idea where.
 
Upvote 0
Is there any way to select the sending account as well in case if I have two outlook email id
With that code you shouldn't need any references set.
Try removing the reference to outlook.
@Fluff - is there a way to choose the sending email account if I have two mail ID's in my outlook
 
Upvote 0

Forum statistics

Threads
1,214,619
Messages
6,120,550
Members
448,970
Latest member
kennimack

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