Forum Discussion
sf49ers19238597
Jun 11, 2025Iron Contributor
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...
m_tarler
Jun 12, 2025Silver 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
sf49ers19238597
Jun 13, 2025Iron Contributor
I'm getting this error message
Thanks You