title: Excel VBA & VB6 Printer
body: <p>I have the following code, this code was written in VB6 but i can not open the form or check any references.</p>
  
  <pre><code>Private Sub PopulatePrinterCombo(cmbDestination As ComboBox)
    Dim objPrinter  As Printer 'a printer in the Printers collection object
  
    'Add the printers to the combo box
    For Each objPrinter In printers
      cmbPrinter.AddItem objPrinter.DeviceName
    Next
  
    'Set current selection to the default printer
    cmbDestination.Text = Printer.DeviceName
  End Sub
  </code></pre>
  
  <p>I am currently copying the code onto Excel VBA macro, the problem is the   <code>Dim objPrinter  As Printer</code>  code, i keep getting an error message saying "USER DEFINED TYPE NOT DEFINED", do i need a reference to add on VBA to be able to get the option of declaring a variable as a "Printer" or something?</p>
  
  <p>My second question is that i do not fully understand the "Printers" in the line  <code>For Each objPrinter In printers</code>, what is "Printers"? can someone please explain that to me.</p>
  
  <p>Thank you</p>
  
  <p><strong>PART 2</strong></p>
  
  <p>I am now trying to print files, i have the following as my code:</p>
  
  <pre><code>  'Initialize values
    intDraftsPrinted = 0
    If objDraftPaths.Count &gt; 1 Then
  
    Else
      intSelectedDraftCount = CountSelectedDrafts
    End If
  
    'prompt user to make sure
    intMsgBoxResponse = MsgBox("You selected " &amp; intSelectedDraftCount &amp; " part numbers. After removing duplicates" &amp; vbNewLine &amp; "there were " &amp; objDraftPaths.Count &amp; " unique draft files found." &amp; vbNewLine &amp; "Do you want to print these files?", vbYesNo, "TD Printer")
  
    If intMsgBoxResponse &lt;&gt; vbYes Then
      intSelectedDraftCount = 0 'So the following for loop will not entered
    Else
      intSelectedDraftCount = objDraftPaths.Count
    End If
  
    For i = 1 To intSelectedDraftCount
  
      booSuccess = False
  
      'open the draft file
      Set objDraftDocument = OpenSolidEdgeDraft(objDraftPaths.Item(i))
      If objDraftDocument Is Nothing Then
        'could not open file
        MsgBox "Could not open the following draft file:" &amp; vbNewLine &amp; _
               objDraftPaths.Item(i), vbExclamation, "Solid Edge Error"
      Else
        'Print the draft file
        For Each objSheet In objDraftDocument.Sheets
          strSheetSize = DetermineSheetSize(objSheet)
          If strSheetSize &lt;&gt; "" Then
            'Determine orientation
            If InStr(1, strSheetSize, "90") &lt;&gt; 0 Then
              'Print as landscape
              intOrientation = vbPRORLandscape
  
            Else
              'Print as portrait
              intOrientation = vbPRORPortrait
            End If
            'Specify Sheet Size
            Select Case Left(strSheetSize, 1)
              Case "A"
                intPaperSize = VBRUN.PrinterObjectConstants.vbPRPSLetter
              Case "B"
                intPaperSize = VBRUN.PrinterObjectConstants.vbPRPS11x17
              Case "C"
                intPaperSize = VBRUN.PrinterObjectConstants.vbPRPSCSheet
              Case "D"
                intPaperSize = VBRUN.PrinterObjectConstants.vbPRPSDSheet
              Case "E"
                intPaperSize = VBRUN.PrinterObjectConstants.vbPRPSESheet
              Case Else
                intPaperSize = VBRUN.PrinterObjectConstants.vbPRPSLetter
            End Select
  
            'Enable error handling
            On Error Resume Next
  
            'Activate the current sheet
            objSheet.Activate
            If Err Then
              'Could not activate sheet
              MsgBox "An error occurred while attempting to print: " &amp; vbNewLine &amp; objDraftPaths.Item(i) &amp; vbNewLine &amp; "The error was:" &amp; vbNewLine &amp; "Error Number: " &amp; Err.Number &amp; vbNewLine &amp; "Error Description: " &amp; Err.Description, vbExclamation, "Solid Edge Error"
              Err.Clear
            Else
              'Print to the printer specified by the combo box
              objDraftDocument.PrintOut cmbPrinter.Text, 1, intOrientation, intPaperSize, , , , igPrintSelected
              If Err Then
                'Could not print document
                MsgBox "An error occurred while attempting to print: " &amp; vbNewLine &amp; objDraftPaths.Item(i) &amp; vbNewLine &amp; "The error was:" &amp; vbNewLine &amp; "Error Number: " &amp; Err.Number &amp; vbNewLine &amp; "Error Description: " &amp; Err.Description, vbExclamation, "Solid Edge Error"
                Err.Clear
              Else
                booSuccess = True
              End If
            End If
  
            'Disable error handling
            On Error GoTo 0
  
          End If
        Next
  
        'Close the file
        objDraftDocument.Close False
  
        intDraftsPrinted = intDraftsPrinted + 1
  
      End If
  
    Next i
  
    'Dereference objects
    Set objSheet = Nothing
    Set objDraftDocument = Nothing
    'Set objDraftPaths = Nothing
  
    PrintSelectedDrafts = intDraftsPrinted
  </code></pre>
  
  <p>Now the problem comes when i hits the line that says: <code>intOrientation = vbPRORLandscape</code>
  in excel VBA, it does not recognize "vbPRORLandscape" as well as the next line "vbPRORPortrait". Is there a way to fix that?</p>
  
  <p>Also, i have a feeling that <code>VBRUN.PrinterObjectConstants.vbPRPSLetter</code> and the rest of those lines might not work out as well. It works in VB6 though.</p>
  
  <p>Thank you</p>