Run-Time error 424 - Export to PDF Sheets - Array

AFidytek

New Member
Joined
Jun 5, 2019
Messages
23
Hi all

I am very new to VB and its mostly thanks to forums like this and a bit of internet searching.

I have a Run-time error 424 - Object required issue

Let me explain what I'm doing:
I have a commandButton that actions SaveAs PDF
The one button has to only export 2 specific sheets to PDF
The msgbox pops up and is giving me the correct filename (which I have selected)
But when I say save after that it ends with the runtime error - I am presuming its the sheets (array argument

Please can someone look at this for me and tell me what I am doing wrong:

Private Sub CommandButton2_Click()
answer = msgbox("Do you want to export the quotation to PDF?", vbYesNo + vbQuestion, "Export Quotation to PDF")
If answer = vbYes Then
filesSaveName = Application.GetSaveAsFilename(Sheet49.Range("N13"), fileFilter:="PDF(*.pdf),*.pdf")
If fileSaveName <> True Then
Sheets(Array("AutoRate Quote Form", "Excess Sheet")).Select
ActiveSheets.ExportAsFixedFormat Type:=xlTypePDF, filename:=fileSaveName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
End If
End If
End Sub

Thanks in advance
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
There's no array in that code.

The only thing I can see that might cause the error you describe is if you don't have a worksheet with the codename Sheet49 in the active worksheet.
 
Upvote 0
Sheet 49 reference is working fine. That's the filename sheet (the active one).

The error is this part i think:

Sheets(Array("AutoRate Quote Form", "Excess Sheet")).Select

Since this is the only difference (besides activesheets & activeworkbook)
 
Upvote 0
Is that the line causing the error?

If it is do you have sheets named 'AutoRate Quote Form' and 'Excess Sheet' in the active workbook?

If it isn't which line is causing the error and what's the error message?
 
Upvote 0
I got it to work:

PHP:
Private Sub CommandButton2_Click()answer = msgbox("Do you want to export the quotation to PDF?", vbYesNo + vbQuestion, "Export Quotation to PDF")If answer = vbYes ThenfileSaveName = Application.GetSaveAsFilename(Sheet49.Range("N13"), fileFilter:="PDF(*.pdf),*.pdf")If fileSaveName <> False ThenSheets(Array("AutoRate Quote Form", "Excess Sheet")).SelectActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, filename:=fileSaveName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True    End IfEnd IfEnd Sub

Thanks for the help Norie

A</div>
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,242
Members
452,623
Latest member
russelllowellpercy

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