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?
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