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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Watch MrExcel Video

Forum statistics

Threads
1,129,804
Messages
5,638,455
Members
417,025
Latest member
MusterDuster

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