Sub MySheetsIntoPdf()
Call ExportSheetsAsPdf(ThisWorkbook.Path & "\TestPdf.pdf", Sheet11, Sheet12, Sheet4)
End Sub
Sub ExportSheetsAsPdf(FileName As String, ParamArray exportedSheets() As Variant)
Dim WB As Workbook
Dim Sheet As Object
Dim i As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set WB = Workbooks.Add
Set Sheet = exportedSheets(LBound(exportedSheets))
Sheet.Copy After:=WB.Sheets(1)
WB.Sheets(1).Delete
For i = LBound(exportedSheets) + 1 To UBound(exportedSheets)
exportedSheets(i).Copy After:=WB.Sheets(WB.Sheets.Count)
Next i
WB.ExportAsFixedFormat XlFixedFormatType.xlTypePDF, FileName, _
Quality:=xlQualityStandard, OpenAfterPublish:=True
WB.Close False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Hello,
Does the code below behave how you expect it to? If I put your sheets in the wrong order in the "MySheetsIntoPdf" method please put them in the order you wish to have them exported in before running the script. Hope that helps!
Code:Sub MySheetsIntoPdf() Call ExportSheetsAsPdf(ThisWorkbook.Path & "\TestPdf.pdf", Sheet11, Sheet12, Sheet4) End Sub Sub ExportSheetsAsPdf(FileName As String, ParamArray exportedSheets() As Variant) Dim WB As Workbook Dim Sheet As Object Dim i As Long Application.ScreenUpdating = False Application.DisplayAlerts = False Set WB = Workbooks.Add Set Sheet = exportedSheets(LBound(exportedSheets)) Sheet.Copy After:=WB.Sheets(1) WB.Sheets(1).Delete For i = LBound(exportedSheets) + 1 To UBound(exportedSheets) exportedSheets(i).Copy After:=WB.Sheets(WB.Sheets.Count) Next i WB.ExportAsFixedFormat XlFixedFormatType.xlTypePDF, FileName, _ Quality:=xlQualityStandard, OpenAfterPublish:=True WB.Close False Application.DisplayAlerts = True Application.ScreenUpdating = True End Sub
Sub ExportSheetsAsPdf(FileName As String, ParamArray exportedSheets() As Variant)
Dim WB As Workbook
Dim Sheet As Variant
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set WB = Workbooks.Add
Do Until WB.Sheets.Count = 1
WB.Sheets(2).Delete
Loop
For Each Sheet In exportedSheets
Sheet.Copy After:=WB.Sheets(WB.Sheets.Count)
Next Sheet
WB.Sheets(1).Delete
WB.ExportAsFixedFormat XlFixedFormatType.xlTypePDF, FileName, _
Quality:=xlQualityStandard, OpenAfterPublish:=True
WB.Close SaveChanges:=False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
I've never done that myself and I'm actually not sure what a PDF bookmark actually is or how to use them in my PDF viewer (which for me is google chrome). A little searching and I found this post that seems to suggest that bookmarks are created at each sheet of the document, but I'm not sure how to tell if it's true or not. Sorry I can't be much more help than that!
https://social.technet.microsoft.co...ks-from-excel-names?forum=officeitproprevious