PageSetups not carried over when saving file as PDF

cirugio

Board Regular
Joined
Mar 30, 2010
Messages
130
Hoping someone can assist. I want to select all worksheets within my workbook and save worksheets into 1 PDF file. I have found some VBA code online (see below) which does this, but unfortunately the PDF file does not have the Page Setups I had previously applied within each worksheet. Each worksheet has Page Setup to have orientation of Landscape and FitToPagesWide / FitToPagesTall to = 1.

Any idea why PageSetups don't come across when saving to PDF ? Any help is greatly appreciated.



Code:
Private Sub Save_File_to_PDF()
 '---- Create a dynamic array which will house all the worksheet names in the workbook to be saved to PDF file
     Dim myArray() As Variant
     Dim i As Integer
     For i = 1 To Sheets.Count
         ReDim Preserve myArray(i - 1)
         myArray(i - 1) = i
     Next i
     
 '--- select all the worksheets within the array so can save to 1 PDF file
     Sheets(myArray).Select    '---- this command seems to reset the PageSetting back to the defaults for some reason???:confused:

    '--- save file ---
      ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
      Filename:="C:\Assets.PDF" , _
      Quality:=xlQualityStandard, _
      IncludeDocProperties:=False, _
      IgnorePrintAreas:=True, _
      OpenAfterPublish:=True
      
 End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,531
Messages
5,837,915
Members
430,520
Latest member
VenkateshRajaganesan

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