Trying to attach pdf to an email with VBA

Pookiemeister

Active Member
Joined
Nov 26, 2015
Messages
319
Office Version
  1. 365
  2. 2010
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
57,030
Office Version
  1. 365
Platform
  1. Windows
Try it with & without.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Pookiemeister

Active Member
Joined
Nov 26, 2015
Messages
319
Office Version
  1. 365
  2. 2010
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)
 

Pookiemeister

Active Member
Joined
Nov 26, 2015
Messages
319
Office Version
  1. 365
  2. 2010
Capture.PNG

Here is what is checked and I am still getting that same Runt-time error.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
57,030
Office Version
  1. 365
Platform
  1. Windows
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.
 

Pookiemeister

Active Member
Joined
Nov 26, 2015
Messages
319
Office Version
  1. 365
  2. 2010

ADVERTISEMENT

Is there away to check?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
57,030
Office Version
  1. 365
Platform
  1. Windows
Probably, but as I don't use outlook, I've no idea where.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,425
Messages
5,642,051
Members
417,251
Latest member
Dordrecht

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
Top