Hi All,

I have an application written in VB.net for batch print jobs. As part of the application, the user selects two printer trays to use to print the batch to (one plain paper the other coloured for coversheets and batch seperators) I had this working until we upgraded our systems from Windows XP with Office 2000 to Windows 7 and Office 2010. Now the selected trays are not being recognised and an error is thrown.

I've looked at similar posts on here and other forums but they seam to concentrate on using some word default trays (wdPrinterDefaultBin etc) however I need to be able to let the user pick whatever tray they wish to use. I don't want to have to go through every printer in the building and map the trays to the word values either as I don't want to rewrite the app everytime we've a new printer.

Here is the code:

sub PopulatePrinterTray (byref Printer as String)
'gets printer trays for selected printer and then populates some comboboxes
Dim pkSource As Printing.PaperSource
Dim printDoc As New Printing.PrintDocument

'Clear the comboboxes
'take printer paper sources i.e. trays
 printDoc.PrinterSettings.PrinterName = Printer
For Each pkSource In printDoc.PrinterSettings.PaperSources
  'dataitem custom class holds a ID and a string (displays string)
   cbDocTray.Items.Add(New DataItem(pkSource.RawKind, pkSource.SourceName))
   cbRedTray.Items.Add(New DataItem(pkSource.RawKind, pkSource.SourceName))
end sub

Sub PrintCover(byref MyCoversheet as String, byref Printer as String, byref RedTray as Long)
Dim oWord As Object = CreateObject("Word.Application")
Dim oDoc As Object = oWord.Documents.open(MyCoversheet)

If InStr(oWord.ActivePrinter, Printer) = 0 Then
      With oWord.Dialogs.Item(wdDialogFilePrintSetup)
        .printer = Printer
        .donotsetassysdefault = True
      End With
End If

 oDoc.PageSetup.FirstPageTray = RedTray 'Error occurs here
    oDoc.PageSetup.OtherPagesTray = RedTray
    oDoc.PrintOut(Range:=wdPrintAllDocument, Item:=wdPrintDocumentContent, Copies:=1)
end sub

As can be seen from above the error happens when setting the tray. There must be a way to do this as Word gives you the printer trays regardless of printer...

This question has already been answered. Start a new discussion instead.