title: Exporting Some Sheets from Excel Workbook to PDF
body: <p>I am working on writing a VBA code to export some of the sheets in excel to same PDF. I have several chart sheets in my excel file each of which name ends with "(name)_Chart".
  I want to export all sheets with names ending wioth chart to one PDF file. 
  Here is the code I am trying to write. </p>
  
  <pre><code>Sub FindWS()
          'look if it at least contains part of the name
          Dim s As Worksheet
          Dim strPath As String
  
          strPath = ActiveWorkbook.Path &amp; "\"
  
          For Each s In ThisWorkbook.Sheets
              If InStr(1, s.Name, Chart) Then
                  s.Activate
                  ActiveSheet.ExportAsFixedFormat xlTypePDF, strPath &amp; s.Name &amp; ".pdf"
                  Exit Sub
              End If
          Next s
  End Sub
  </code></pre>
  
  <p>This code is not limting export to only the chart sheets but exporting thy whole workbook. Can anyone help me with figurint out whats is missing in my code.</p>
  
  <p>Thanks!</p>
  
  <p><strong>MODIFIED CODE:</strong></p>
  
  <pre><code>Sub FindWS()
  'look if it at least contains part of the name
  Dim s As Worksheet
  Dim strPath As String
  
  strPath = ActiveWorkbook.Path &amp; "\"
  
  For Each s In ThisWorkbook.Worksheets
        If InStr(1, s.Name, "Chart") = 0 Then
            ' Hide the sheet so it is not exported as PDF
            s.Visible = False
               End If
  Next s
            With ActiveWorkbook
            .ExportAsFixedFormat xlTypePDF, strPath &amp; "TEST.pdf"
                  End With
  </code></pre>
  
  <p>End Sub</p>