VBA Button to Convert to PDF Doesn't Print in Correct Sequence

sabbuck

New Member
Joined
Aug 21, 2017
Messages
24
Hi,

I have an Excel workbook with 19 sheets. There is a menu page with buttons to go to 6 of these sheets to fill in data. The rest are all very hidden. on the menu page there is a button to convert the workbook to PDF but only for 9 of the sheets in the workbook, I don't want the rest converted to the PDF. The button and VBA code work fine, it converts to PDF but for some reason the sheet named "Investments" comes out as the first page. The rest are all in the correct sequence. In page setup I have changed the first page number to 11 for this sheet (as that's the page number it should be), and it is numbered correctly in the footer when it converts to PDF, but I've no idea what I'm doing wrong in the below code to make it come out as the first page.

Can anyone see my mistake?

VBA Code:
Public Sub Create_BaseCaseProjections_PDF()

    Dim currentSheet As Worksheet
    
    Application.ScreenUpdating = False
    With ThisWorkbook
        Set currentSheet = .ActiveSheet
        .Worksheets("Cover").Visible = xlSheetVisible
        .Worksheets("Contents").Visible = xlSheetVisible
        .Worksheets("Reference Points").Visible = xlSheetVisible
        .Worksheets("Asset Split").Visible = xlSheetVisible
        .Worksheets("Income.Statement").Visible = xlSheetVisible
        .Worksheets("Bal.Sheet").Visible = xlSheetVisible
        .Worksheets("Investments").Visible = xlSheetVisible
        .Worksheets("Inc+Resr").Visible = xlSheetVisible
        .Worksheets("Appendix").Visible = xlSheetVisible
        .Worksheets(Array("Cover", "Contents", "Reference Points", "Asset Split", "Income.Statement", "Bal.Sheet", "Investments", "Inc+Resr", "Appendix")).Select
        .ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=.Path & "\Base Case Projections.pdf", _
            Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
        .Worksheets(Array("Cover", "Contents", "Reference Points", "Asset Split", "Income.Statement", "Bal.Sheet", "Investments", "Inc+Resr", "Appendix")).Visible = xlSheetHidden
        currentSheet.Select
    End With
    Application.ScreenUpdating = True
    
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
There is nothing wrong with your code. The Array function does not determine the print order.
The order in which the tabs are arranged (on your screen) determines the print order.
 
Upvote 0
You are welcome and thanks for letting me know.
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,323
Members
449,077
Latest member
jmsotelo

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