Syntax error in code for "Save to PDF" button

tripodgod

New Member
Joined
Dec 22, 2013
Messages
16
Hello again,

Got myself in a right muddle with a command button. All i want it to do is generate the pre populated form on sheet8 as a PDF, then open it. I tried this code:

Code:
Sub ExportAsFixedFormat()
    Type As XlFixedFormatType
    Filename As Object
    Quality As Object
    IncludeDocProperties As Object
    IgnorePrintAreas As Object
    From As Object
    To As Object
    OpenAfterPublish As Object
    FixedFormatExtClassPtr As Object

End Sub

Private Sub CommandButton8_Click()
Dim ws As Worksheet
Set ws = Sheet8

ws.ExportAsFixedFormat (XlFixedFormatType.xlTypePDF, Filename:= "ON", , , , , ,OpenAfterPublish:= TRUE, ,)

End Sub

I tried to do it with and without the names eg:

Code:
ws.ExportAsFixedFormat (XlFixedFormatType.xlTypePDF, ON, , , , , , TRUE, ,)

I get either a "Syntax error" or an "Expected expression". I have written this entire program as a complete newbie to code, and really appreciate all the help i have had from this site. So thank you in advance!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Code:
i recorded a macro of exporting a worksheet to macro and got this

[COLOR=#ff0000]ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _[/COLOR]
[COLOR=#ff0000]                                Filename:="F:\test.pdf", _[/COLOR]
[COLOR=#ff0000]                                Quality:=xlQualityStandard, _[/COLOR]
[COLOR=#ff0000]                                IncludeDocProperties:=True, _[/COLOR]
[COLOR=#ff0000]                                IgnorePrintAreas:=False, _[/COLOR]
[COLOR=#ff0000]                                OpenAfterPublish:=False[/COLOR]


so yours is


[COLOR=#ff0000]Sheet8.ExportAsFixedFormat Type:=xlTypePDF, _[/COLOR]
[COLOR=#ff0000]                           Filename:="ON", _[/COLOR]
[COLOR=#ff0000]                           Quality:=xlQualityStandard, _[/COLOR]
[COLOR=#ff0000]                           IncludeDocProperties:=True, _[/COLOR]
[COLOR=#ff0000]                           IgnorePrintAreas:=False, _[/COLOR]
[COLOR=#ff0000]                           OpenAfterPublish:=False[/COLOR]
 
Upvote 0
Code:
i recorded a macro of exporting a worksheet to macro and got this

[COLOR=#ff0000]ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _[/COLOR]
[COLOR=#ff0000]                                Filename:="F:\test.pdf", _[/COLOR]
[COLOR=#ff0000]                                Quality:=xlQualityStandard, _[/COLOR]
[COLOR=#ff0000]                                IncludeDocProperties:=True, _[/COLOR]
[COLOR=#ff0000]                                IgnorePrintAreas:=False, _[/COLOR]
[COLOR=#ff0000]                                OpenAfterPublish:=False[/COLOR]


so yours is


[COLOR=#ff0000]Sheet8.ExportAsFixedFormat Type:=xlTypePDF, _[/COLOR]
[COLOR=#ff0000]                           Filename:="ON", _[/COLOR]
[COLOR=#ff0000]                           Quality:=xlQualityStandard, _[/COLOR]
[COLOR=#ff0000]                           IncludeDocProperties:=True, _[/COLOR]
[COLOR=#ff0000]                           IgnorePrintAreas:=False, _[/COLOR]
[COLOR=#ff0000]                           OpenAfterPublish:=False[/COLOR]

Thank you very much, worked like a charm.
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,930
Members
452,367
Latest member
TePunaBloke

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