Trying to get Excel to send a sheet as a PDF

DipDip

Board Regular
Joined
Jan 23, 2015
Messages
76
Office Version
  1. 2016
Platform
  1. Windows
Hiya Peeps,
I wonder if someone can help me with this. I am trying to get the code to select the right data via autofilter, then email the sheet as a PDF.

I have the following code:
Code:
Sub Sort1()
'
    ActiveSheet.Range("$AB$4:$AB$350").AutoFilter Field:=1, Criteria1:=Array( _
        "Care Assistant", "RGN", "Senior Care ***..."), Operator:=xlFilterValues


ChDir "K:\Payroll\"
ActiveSheet.ExportAsFixedFormat Type:=x1TypePDF, Filename:= _
"K:\Payroll\testsave.pdf", OpenAfterPublish:=False


Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim myAttachments As Object


Set OutLookApp = CreateObject(“Outlook.application”)
Set OutLookMailItem = OutLookApp.CreateItem(0)
Set myAttachments = OutLookMailItem.Attachments


With OutLookMailItem
.To = “”
.Subject = "Time Sheets"
.Body = "Please check these and let me know if they are correct or not."
myAttachments.Add "K:\Payroll\testsave.pdf"
‘.send
.Display
End With


Set OutLookMailItem = Nothing
Set OutLookApp = Nothing
End Sub

However I get the following error:

Code:
Run-time error '424':

Object required

and this is the bit that is highlighted:

Code:
Set OutLookApp = CreateObject(“Outlook.application”)

Cheers with the help in advance peeps :D
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
I have Outlook 16.0 object library ticked in that section.
 
Upvote 0
Looks like some of your double quotes are wrong
Code:
Set OutLookApp = CreateObject([COLOR=#ff0000]“[/COLOR]Outlook.application[COLOR=#ff0000]”[/COLOR])
Set OutLookMailItem = OutLookApp.CreateItem(0)
Set myAttachments = OutLookMailItem.Attachments


With OutLookMailItem
.To =[COLOR=#ff0000] “”[/COLOR]
They should be "" not “”
 
Upvote 0
Solution
Looks like some of your double quotes are wrong
Code:
Set OutLookApp = CreateObject([COLOR=#ff0000]“[/COLOR]Outlook.application[COLOR=#ff0000]”[/COLOR])
Set OutLookMailItem = OutLookApp.CreateItem(0)
Set myAttachments = OutLookMailItem.Attachments


With OutLookMailItem
.To =[COLOR=#ff0000] “”[/COLOR]
They should be "" not “”

Awesome! That sorted out that issue, but not it still comes back with the same error for the following bit of code:

Rich (BB code):
‘.send
 
Upvote 0
Basically the same thing it should be ' not`
 
Upvote 0
Yeah just realised what I wrote and that I'm an idiot :laugh:. Cheers everyone! Much appreciated!!!
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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