Forum Discussion
I need help create a pdf with a button
Private Sub CREATE_GARY_TEAMS_PDF_Click() Dim FilePath As String ' Specify the output file path FilePath = ThisWorkbook.Path & "\GARY NFL TEAMS SCHEDULE.pdf" ' Select the sheets you want to export as ONE PDF Dim SheetArray As Variant SheetArray = Array("STEELERS FOR FRIENDS", "CHARGERS FOR FRIENDS", "RAIDERS FOR FRIENDS", "COWBOYS FOR FRIENDS", COWBOYS FOR FRIENDS" , COWBOYS FOR FRIENDS""EAGLES FOR FRIENDS", "BEARS FOR FRIENDS", "49ERS FOR FRIENDS", "49ERS FOR FRIENDS", "CARDINALS FOR FRIENDS", "RAMS FOR FRIENDS") ' Ensure sheets exist before proceeding Dim ws As Worksheet, i As Integer For i = LBound(SheetArray) To UBound(SheetArray) On Error Resume Next Set ws = ThisWorkbook.Sheets(SheetArray(i)) If ws Is Nothing Then MsgBox "Sheet '" & SheetArray(i) & "' not found!", vbExclamation, "Error" Exit Sub End If On Error GoTo 0 Next i ' Export sheets as a single PDF ThisWorkbook.Sheets(SheetArray).Select ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, _ Filename:=FilePath, _ Quality:=xlQualityStandard, _ IncludeDocProperties:=True, _ IgnorePrintAreas:=False, _ OpenAfterPublish:=True ' Deselect sheets to prevent selection issues ThisWorkbook.Sheets(1).Select ' Adjust to a default sheet MsgBox "PDF saved at: " & FilePath, vbInformation, "Export Complete""" End Sub
- Steelers
- Chargers
- Raiders
- Cowboys x3
- Eagles
- Bears
- 49ers X2
- Cardinals
- Rams
I have a worksheet called Button on that is enabled. I need help adding 2 more Cowboys. button. I tried putting a button worksheet in a PDF. file, I do not want that
Thanks You
5 Replies
- sf49ers19238597Iron Contributor
- m_tarlerBronze Contributor
I have tried to re-format that. Try this:
Private Sub CREATE_GARY_TEAMS_PDF_Click() Dim FilePath As String ' Specify the output file path FilePath = ThisWorkbook.Path & "\GARY NFL TEAMS SCHEDULE.pdf" ' Select the sheets you want to export as ONE PDF Dim SheetArray As Variant SheetArray = Array("STEELERS FOR FRIENDS", "CHARGERS FOR FRIENDS", "RAIDERS FOR FRIENDS", "COWBOYS FOR FRIENDS", "COWBOYS FOR FRIENDS", "COWBOYS FOR FRIENDS", "EAGLES FOR FRIENDS", "BEARS FOR FRIENDS", "49ERS FOR FRIENDS", "49ERS FOR FRIENDS", "CARDINALS FOR FRIENDS", "RAMS FOR FRIENDS") ' Ensure sheets exist before proceeding Dim ws As Worksheet, i As Integer For i = LBound(SheetArray) To UBound(SheetArray) On Error Resume Next Set ws = ThisWorkbook.Sheets(SheetArray(i)) If ws Is Nothing Then MsgBox "Sheet '" & SheetArray(i) & "' not found!", vbExclamation, "Error" Exit Sub End If On Error GoTo 0 Next i ' Export sheets as a single PDF ThisWorkbook.Sheets(SheetArray).Select ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, _ Filename:=FilePath, _ Quality:=xlQualityStandard, _ IncludeDocProperties:=True, _ IgnorePrintAreas:=False, _ OpenAfterPublish:=True ' Deselect sheets to prevent selection issues ThisWorkbook.Sheets(1).Select ' Adjust to a default sheet MsgBox "PDF saved at: " & FilePath, vbInformation, "Export Complete" End Sub- sf49ers19238597Iron Contributor
I'm getting this error message
Thanks You
First thing, to use the below to include "COWBOYS FOR FRIENDS":
Dim SheetArray As Variant SheetArray = Array("STEELERS FOR FRIENDS", "CHARGERS FOR FRIENDS", "RAIDERS FOR FRIENDS", _ "COWBOYS FOR FRIENDS", "COWBOYS FOR FRIENDS", "COWBOYS FOR FRIENDS", _ "COWBOYS FOR FRIENDS", "COWBOYS FOR FRIENDS", "EAGLES FOR FRIENDS", _ "BEARS FOR FRIENDS", "49ERS FOR FRIENDS", "49ERS FOR FRIENDS", _ "CARDINALS FOR FRIENDS", "RAMS FOR FRIENDS")