Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Tacoma, Washington, USA
    Posts
    431
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Printing to Different Trays Based on PrintDriver

    For many long years we’ve been very fortunate to only use one printer make and model through the building. Everyone is setup to use the same print driver. I used the following macro on a custom toolbar saved to the shared startup folder. Our letterhead has two sections by default. This macro is particularly help for when they need to print a letter. It involves two Forms, one named frmPaperSelect2 asking which tray and one named frmPrint asking how many copies. Here is code for frmPaperSelect2:
    Code:
    Private Sub ContinueButton_Click()
        If OptionLetterhead1 = True Then
            With ActiveDocument.PageSetup
                .FirstPageTray = wdPrinterLowerBin
                .OtherPagesTray = wdPrinterLowerBin
            End With
        End If
        If OptionPlain2 = True Then
            With ActiveDocument.PageSetup
                .FirstPageTray = wdPrinterLargeCapacityBin
                .OtherPagesTray = wdPrinterLargeCapacityBin
            End With
        End If
        If OptionManualFeed3 = True Then
            With ActiveDocument.PageSetup
                .FirstPageTray = wdPrinterUpperBin
                .OtherPagesTray = wdPrinterUpperBin
            End With
        End If
        Unload frmPaperSelect2
        frmPrint.Show
    End Sub
    Private Sub UserForm_Click()
    frmPaperSelect.Hide
    End Sub
    But nothing that good lasts forever. This year we will be slowly rolling out new models, one already being in use. The tray names are different for that make and model printer. By the time I purchase more printers it may be yet a different one. For the new printer users the above macro fails because of the tray name change. I could write another macro just like this one but would much rather have only one custom print button for everyone. Especially since we will likely have at least three different models to content with soon.

    My thought is to modify the macro such that it looks for and identifies the print driver and adjusts to print based on that print driver. Effectively:

    If HP Laserjet 4100 PCL 5e, print to wdPrinterLargeCapacityBin.
    If HP Laserjet 4350 PCL 6, print manual to 261.

    The problem is I don’t know how to write that. So far as a test macro I have this but it doesn’t work:

    Code:
    Sub Module2()
    Dim sDriver As String
    sDriver = GetPrinterDetails.DriverName
    If InStr(sDriver, "HP LaserJet 4100 PCL 5e") > 0 Then
       With ActiveDocument.PageSetup
           .FirstPageTray = wdPrinterLowerBin
           .OtherPagesTray = wdPrinterLowerBin
       End With
       Application.PrintOut Copies:=1
    ElseIf InStr(sDriver, "HP Laserjet 4350 PCL 6") > 0 Then
       With ActiveDocument.PageSetup
           .FirstPageTray = 260
           .OtherPagesTray = 260
       End With
       Application.PrintOut Copies:=1
     
    Else: MsgBox "Driver Name is: " & sDriver, vbOKOnly
    End If
    End Sub
    Could someone lend me a hand on this?
    Daisy

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    I was going to suggest ActivePrinter, but that only gets you the name, not the driver. If your IT has named the printers with driver information (e.g., PostScript vs. PCL), that might be available as part of ActivePrinter. Otherwise, I'm not sure how you get it.

    GetPrinterDetails isn't defined for me (or is that a Windows API call?).

  3. #3
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Tacoma, Washington, USA
    Posts
    431
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I got the idea from this:

    http://pubs.logicalexpressions.com/p...cle.asp?id=183

    It lists DriverName as an available piece of printer information. It made the most sense because if I have three printers, there will be an equal three print drivers to contend with. The printers are named using their asset tag or the location. For example, my printer is User Support but Joanne's printer is HP000473. The printer name and share name are usually the same name.
    Daisy

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Aha, lots of extra API code. So if you Debug.Print sDriver to the Immediate window, does it appear to provide useful information? If so, what part of the code isn't working?

  5. #5
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Tacoma, Washington, USA
    Posts
    431
    Thanks
    0
    Thanked 3 Times in 3 Posts
    I added Debug.Print sDriver like this:

    Dim sDriver As String
    sDriver = GetPrinterDetails.DriverName
    Debug.Print sDriver

    When I step into it with debug it stops at "sDriver = GetPrinterDetails.DriverName" with Run-Time Error 424.
    Daisy

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    Sorry, I don't know error numbers by heart. Did you copy that huge slug of API code into your document/template? Here's a sample that seems to work.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •