title: Excel VBA Workbook Printout Method
body: <p>I am writing a VBA macro to convert excel workbooks to PDF.
  The wkb.PrintOut method works fine for some excel files. But for the others, it will print the first worksheet to the file name I supplied, and prompt me for the file name to save for the remaining worksheets.</p>
  
  <p>Why does the PrintOut function behaves such a way? How do I let it print the entire workbook into a single file name I set?</p>
  
  <pre><code>Public Sub ConvertToPDF()
  Dim ws As Worksheet
  Dim inputQueue As Collection
  Dim outputQueue As Collection
  Dim r As Integer, c As Integer
  Dim objFSO As FileSystemObject
  Dim objInputFolder As Folder
  Dim objOutputFolder As Folder
  Dim objInputFile As File
  Dim fileExt As String
  
  Set ws = Worksheets("XLPrint")
  Set objFSO = New FileSystemObject
  Set inputQueue = New Collection
  Set outputQueue = New Collection
  Application.ActivePrinter = "Microsoft Print to PDF on Ne02:"
  
  Application.DisplayAlerts = False
  r = ws.Range("folder_name").Row + 1
  c = ws.Range("folder_name").Column
  
  ClearCollection inputQueue
  ClearCollection outputQueue
  
  While (ws.Cells(r, c).Value &lt;&gt; "")
      inputQueue.Add objFSO.GetFolder(ws.Cells(r, c).Value)
      outputQueue.Add objFSO.GetFolder(ws.Cells(r, c + 1).Value)
      r = r + 1
  Wend
  
  Application.ScreenUpdating = False
  
  Do While inputQueue.Count &gt; 0
      Set objInputFolder = inputQueue(1)
      inputQueue.Remove 1
      Set objOutputFolder = outputQueue(1)
      outputQueue.Remove 1
  
      For Each objInputFile In objInputFolder.Files
          fileExt = Mid(objInputFile.ShortName, InStr(objInputFile.ShortName, ".") + 1)
          Select Case UCase(fileExt)
              Case "XLSX", "XLSM", "XLS"
                  Call PrintXLToPDF(objInputFile, objOutputFolder)
              Case "DOCX", "DOC"
                  Call PrintWordToPDF(objInputFile, objOutputFolder)
          End Select
      Next objInputFile
  Loop
  Application.ScreenUpdating = True
  
  Application.DisplayAlerts = True
  Set objFSO = Nothing
  Set ws = Nothing
  Set inputQueue = Nothing
  Set outputQueue = Nothing
  MsgBox "Done"
  
  End Sub
  
  Public Sub PrintXLToPDF(ByVal objInputXL As File, ByVal objOutputFolder As Folder)
  
  Dim wkb As Workbook
  Dim outputFileName As String
  
  Set wkb = Workbooks.Open(objInputXL.Path)
  outputFileName = objOutputFolder.ShortPath &amp; "\" &amp; Mid(objInputXL.Name, 1, InStr(objInputXL.Name, ".") - 1) &amp; ".pdf"
  wkb.PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False, PrToFileName:=outputFileName, ActivePrinter:="Microsoft Print to PDF on Ne02:"
  wkb.Close SaveChanges:=False
  
  Set wkb = Nothing
  End Sub
  </code></pre>