Results 1 to 10 of 10
  1. #1
    New Lounger
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VB/VBA Call to determine printer type? (Word 2000)

    Hi: I have a question; one that I cannot seem to find any information on anywhere ... I feel it is a common-enough problem that many firms would have ... It has to do with printing different paper types to different printers

    OK, in my office I have several different types of HP printers: HP4+, HP5, HP4050. The only thing that is consistent about these printers is that they have the following tray setups: envelope feeder, MP/Tray1, Tray2, and Tray3.

    I have more paper types than I do trays: draft, bond, 1stpageletterhead, 2ndpageletterhead, legal, labels, envelopes

    So: I would like to standardize what trays will hold what type of paper:

    Envelopes Envelope Feeder
    MP/Tray1 2nd page letterhead
    Tray2 1st page letterhead
    Tray3 Draft

    MP/Tray1 Legal, labels, etc.
    (prompted)


    I want to create a macro that will set the proper paper trays depending on the type of document produced: e.g. "Letter" would set the first page of the document to Tray2 and all subsequent pages to Tray3.
    OK, I can do that. However, the macro only works for HP4050 printers. HP5 printers don't have a "Tray3", they have "Lower Bin".

    Now that I got that all out of the way, here is what I want: A macro that determines the "type" of printer (HP4+, HP5), and then sets the appropriate tray codes. I can get the tray codes my creating the macro for just one printer at a time (whatever my default printer is). What I can't seem to figure out is whether or not I can tell what type of printer my default printer is, so that I can use a SELECT CASE or IF/THEN statement to set the tray codes. Is there a VB or VBA call that will return this information?

    Thanks for whatever help you can give ...

    Andrew Harrell (VBA newbie)
    Greenberg, Traurig
    harrella@gtlaw.com

  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

    Re: VB/VBA Call to determine printer type? (Word 2000)

    Okay, just for historical reference, I found this code I used in a very old version of Word, probably Word95 (as interpreted by Word2000):

    <pre>Dim fps2 As Object
    Set fps2 = WordBasic.DialogRecord.FilePrintSetup(False)
    WordBasic.CurValues.FilePrintSetup fps2
    curPrinter$ = fps2.Printer

    Rem Get printer [driver] type (i.e., 4 or 4si) from the local Registry
    curPtrRegKey$ = _
    "HKEY_LOCAL_MACHINESystemCurrentControlSetcontrolP rintPrinters" + _
    curPrinter$
    curPtrType$ = _
    WordBasic.[GetPrivateProfileString$](curPtrRegKey$, "Printer Driver", "")</pre>

    Lovely, eh? To do this in VBA would be:
    <pre>Sub DiscoverPrinter()
    Dim strPrinter As String, strDriver As String
    'retrieve full printer name and port string
    strPrinter = Application.ActivePrinter
    'strip port information
    strPrinter = Left(strPrinter, InStr(1, strPrinter, " on ", vbBinaryCompare) - 1)
    'look up driver name
    strDriver = System.PrivateProfileString("", "HKEY_LOCAL_MACHINESystem" & _
    "CurrentControlSetcontrolPrintPrinters" & strPrinter, _
    "Printer Driver")
    'report findings
    MsgBox strPrinter & " is a(n) " & strDriver
    End Sub</pre>

    Hope this helps, and please post back with the working solution; you will earn lots of fans! (And then I won't feel guilty about helping out the competition. <img src=/S/wink.gif border=0 alt=wink width=15 height=15>)

  3. #3
    New Lounger
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB/VBA Call to determine printer type? (Word 2000)

    Will be happy to do so ... will need to get with some of my more-experienced colleagues to apply ... but will post back.

    Many Thanks!!

  4. #4
    5 Star Lounger
    Join Date
    Dec 2000
    Location
    Tallahassee, Florida, USA
    Posts
    901
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB/VBA Call to determine printer type? (Word 2000)

    <img src=/S/crybaby.gif border=0 alt=crybaby width=15 height=15>
    Close, but no cigar on our system... we're running Win2k on Win2k Workstations and Win2k server...

    Any suggestions?
    Attached Images Attached Images
    Karen

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VB/VBA Call to determine printer type? (Word 2000)

    Oh, man. After an hour in the Registry it's time to go home! Here is a version that works with Windows 2000 Professional on the one PC I could try it on:

    <pre>Sub DiscoverPrinter()
    Dim strPrinter As String, strDriver As String, strServer() As String
    'retrieve full printer name and port info
    strPrinter = Application.ActivePrinter
    'strip port information from printer name (necessary for Win98)
    strPrinter = Left(strPrinter, InStr(1, strPrinter, " on ", vbBinaryCompare) - 1)
    'look up driver name
    strDriver = System.PrivateProfileString("", "HKEY_LOCAL_MACHINESystem" & _
    "CurrentControlSetcontrolPrintPrinters" & strPrinter, _
    "Printer Driver")
    'if driver name is blank, try key for Windows2000
    If strDriver = vbNullString Then
    'parse server name from share name
    strServer = Split(strPrinter, "", , vbTextCompare)
    strDriver = System.PrivateProfileString("", "HKEY_LOCAL_MACHINESoftware" & _
    "MicrosoftWindows NTCurrentVersionPrintProvidersLanMan Print Services" & _
    "Servers" & strServer(2) & "Printers" & strServer(3), "Printer Driver")
    End If
    'report findings
    MsgBox strPrinter & " is a(n) " & strDriver
    End Sub</pre>

    Let me know how it works out.

  6. #6
    New Lounger
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB/VBA Call to determine printer type? (Word 2000)

    Hey, thanks for the effort and the code! It did work -- I found the same registry data earlier in the evening, and fumbled thru getting the strDriver parsed to get to the share name (not as elegant as you did it). And it did work!!

    Next step is to put in the conditionals for the printer driver types ... will post the code as soon as Karen and I have tested .... thanks again!

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB/VBA Call to determine printer type? (Word 2000)

    API calls should help in identifying printer.

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VB/VBA Call to determine printer type? (Word 2000)

    Yeah, but which ones? <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB/VBA Call to determine printer type? (Word 2000)

    A good source for this is the bible, ooops, I mean Dan Appleman's Visual Basic Guide to the Win32 API (ISBN: 0672315904), check for best price at www.bookpool.com and www.bestbookbuys.com.

  10. #10
    New Lounger
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VB/VBA Call to determine printer type? (Word 2000)

    OK, I've got the code ... many thanks for what would have been the hard part for me to figure out -- the registry lookup , etc ...

    A little info on the completed macro -- I am not an HP printer expert. A big part of getting this macro to work was to check every printer(actually the driver) and then see what settings are made when different printers are used as the default printer.

    Well .... Enjoy, and let me know what you think about my first effort here .......

    '*** Document Paper Type Macro ****************************
    '
    'Written by: Andrew Harrell on: 8/06/01
    '
    '************************************************* *********

    Option Explicit 'turn on required var declaration
    'Give the paper types a name; easier to follow code
    Private Enum gtPaperType
    draft = 1
    Letterhead = 2
    Other = 3
    End Enum

    'These next three subs form the macs for the toolbar
    Public Sub SelDraftPaper()
    Call DiscoverPrinter(draft)
    End Sub
    Public Sub SelLHPaper()
    Call DiscoverPrinter(Letterhead)
    End Sub
    Public Sub SelOtherPaper()
    Call DiscoverPrinter(Other)
    End Sub

    ' ************************************************** ********
    ' Discover Default Printer (by printer driver)
    ' ************************************************** ********
    Private Sub DiscoverPrinter(ByVal intChoice As gtPaperType)
    Dim strPrinter As String, strdriver As String, strServer() As String

    ' *** Retrieve full printer name and port string
    strPrinter = Application.ActivePrinter
    ' *** Strip port information
    strPrinter = Left(strPrinter, InStr(1, strPrinter, " on ", vbBinaryCompare) - 1)
    ' *** Parse server name from share name
    strServer = Split(strPrinter, "", , vbTextCompare)
    ' *** Look up driver name in Registry
    strdriver = System.PrivateProfileString("", "HKEY_LOCAL_MACHINESoftware" & _
    "MicrosoftWindows NTCurrentVersionPrintProvidersLanMan Print Services" & _
    "Servers" & strServer(2) & "Printers" & strServer(3), "Printer Driver")

    ' *** Now call the proper Printer subroutine to set the bins
    Select Case strdriver
    Case Is = "HP LaserJet 5"
    Call HP5BINZ(intChoice)
    Case Is = "HP LaserJet 5N"
    Call HP5BINZ(intChoice)
    Case Is = "HP LaserJet 4 Plus"
    Call HP5BINZ(intChoice)
    Case Is = "HP LaserJet 4000 Series PCL"
    Call HP4000BINZ(intChoice)
    Case Is = "HP LaserJet 4050 Series PCL"
    Call HP4000BINZ(intChoice)
    Case Else
    MsgBox Prompt:="You must manually set Paper trays" & vbLf & "for this Printer: " & strdriver, _
    Buttons:=vbOKOnly + vbInformation, Title:="Set Paper Trays"
    End Select

    End Sub
    ' ************************************************** ********
    ' End of Macro
    ' ************************************************** ********

    Private Sub HP5BINZ(ByVal intChoice As gtPaperType)
    '
    ' HP5BINZ Macro
    ' Macro recorded 8/01/2001 by Harrella
    '
    With ActiveDocument.PageSetup

    Select Case intChoice
    Case Is = gtPaperType.draft
    .FirstPageTray = wdPrinterDefaultBin
    .OtherPagesTray = wdPrinterDefaultBin
    Case Is = gtPaperType.Letterhead
    .FirstPageTray = wdPrinterLowerBin
    .OtherPagesTray = wdPrinterUpperBin
    Case Is = gtPaperType.Other
    .FirstPageTray = wdPrinterManualFeed
    .OtherPagesTray = wdPrinterManualFeed
    End Select

    End With
    End Sub

    Private Sub HP4000BINZ(ByVal intChoice As gtPaperType)
    '
    ' HP4000BINZ Macro
    ' Macro recorded 8/01/2001 by Harrella
    '
    With ActiveDocument.PageSetup

    Select Case intChoice
    Case Is = gtPaperType.draft
    .FirstPageTray = wdPrinterDefaultBin
    .OtherPagesTray = wdPrinterDefaultBin
    Case Is = gtPaperType.Letterhead
    .FirstPageTray = 260
    .OtherPagesTray = 261
    Case Is = gtPaperType.Other
    .FirstPageTray = 257
    .OtherPagesTray = 257
    End Select

    End With
    End Sub

Posting Permissions

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