VBA to Export Specific Worksheets to PDF

franswa3434

Board Regular
Joined
Sep 16, 2014
Messages
69
Hey everyone,

I'm trying to create a VBA that will export 2 specific hidden worksheets to a PDF file, but i can't get it to work.

Here is my code:

Private Sub CommandButton1_Click()

Sheet10.Visible = True
Sheet12.Visible = True
Sheets(Array(Sheet10, Sheet12)).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:= _
"C:\Temp\Letter of Intent.pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
Sheet10.Visible = False
Sheet12.Visible = False

End Sub

Any and all help would be appreciated.

Thanks!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Does it also work if i want to Export a selection of data from an invoice to an Excel sheet?

Thanks
 
Upvote 0
I'd be curious as to if this worked out for you. Your formatting was a little off here and sometimes it can make a difference.

Type:=xlTypePDF, FileName:= _
"C:\Temp\Letter of Intent.pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _

Code:
Sub exportpdf()
Sheets("sheet10").Visible = xlSheetVisible
Sheets("sheet12").Visible = xlSheetVisible
  ThisWorkbook.Sheets(Array("Sheet10", "Sheet12")).Select
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
        Filename:="C:\temp\LetterofIntent.pdf", _
        Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, _
        OpenAfterPublish:=True
Sheets("sheet10").Visible = xlVeryHidden
Sheets("sheet12").Visible = xlVeryHidden
End Sub
 
Upvote 0
I literally just got it.

I was hoping to use the sheet number and not the sheet name, but i got it to work

Sheet10.Visible = True
Sheet12.Visible = True

Sheets(Array("Letter of Intent", "Summary Page")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FolderPath1 & Sheet3.Range("I11") _
& FolderPath2 & CustomerName & " - Letter of Intent - " & TodayDate, _
openafterpublish:=True, ignoreprintareas:=False

Sheet10.Visible = False
Sheet12.Visible = False
 
Upvote 0
When you say "sheet number" do you mean the code name for the sheet? If so, try...

Code:
[COLOR=#333333]Sheets(Array(Sheet10.Name, Sheet12.Name)).Select[/COLOR]

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,718
Members
448,986
Latest member
andreguerra

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