Forum Discussion

sf49ers19238597's avatar
sf49ers19238597
Iron Contributor
Jun 11, 2025

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

 

  1. Steelers
  2.  Chargers
  3.  Raiders
  4.  Cowboys  x3
  5.  Eagles 
  6.  Bears
  7.  49ers X2
  8.  Cardinals
  9.  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

    • m_tarler's avatar
      m_tarler
      Bronze 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
      

       

  • 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")

     

     

     

Resources