title: Generate separate PDF from Sheets in VBA
body: <p>I am trying to create a macro that will generate separate PDF files for Selected Worksheets in a Workbook. I found this code on line, which works great, it puts all selected sheets in ONE PDF. I need to have each selected sheet as a separate PDF.</p>
  <p>I am a beginner to VBA.</p>
  <pre><code>Sub PDFActiveSheet()
  
  Dim wsA As Worksheet
  Dim wbA As Workbook
  Dim strTime As String
  Dim strName As String
  Dim strPath As String
  Dim strFile As String
  Dim strPathFile As String
  Dim myFile As Variant
  On Error GoTo errHandler
  
  Set wbA = ActiveWorkbook
  Set wsA = ActiveSheet
  strTime = Format(Now(), &quot;yyyymmdd\_hhmm&quot;)
  
  'get active workbook folder, if saved
  strPath = wbA.Path
  If strPath = &quot;&quot; Then
    strPath = Application.DefaultFilePath
  End If
  strPath = strPath &amp; &quot;\&quot;
  
  'replace spaces and periods in sheet name
  strName = Replace(wsA.Name, &quot; &quot;, &quot;&quot;)
  strName = Replace(strName, &quot;.&quot;, &quot;_&quot;)
  
  'create default name for savng file
  strFile = strName &amp; &quot;_&quot; &amp; strTime &amp; &quot;.pdf&quot;
  strPathFile = strPath &amp; strFile
  
  'use can enter name and
  ' select folder for file
  myFile = Application.GetSaveAsFilename _
      (InitialFileName:=strPathFile, _
          FileFilter:=&quot;PDF Files (*.pdf), *.pdf&quot;, _
          Title:=&quot;Select Folder and FileName to save&quot;)
  
  'export to PDF if a folder was selected
  If myFile &lt;&gt; &quot;False&quot; Then
      wsA.ExportAsFixedFormat _
          Type:=xlTypePDF, _
          Filename:=myFile, _
          Quality:=xlQualityStandard, _
          IncludeDocProperties:=True, _
          IgnorePrintAreas:=False, _
          OpenAfterPublish:=False
      'confirmation message with file info
      MsgBox &quot;PDF file has been created: &quot; _
        &amp; vbCrLf _
        &amp; myFile
  End If
  
  exitHandler:
      Exit Sub
  errHandler:
      MsgBox &quot;Could not create PDF file&quot;
      Resume exitHandler
  End Sub
  </code></pre>