Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Change printer name for one print job (VB 6.3)

    Hi everyone (glad to see the Lounge back!),

    I am trying to modify normal.dot by creating a new button to add to our standard toolbar with some very specific code - I don't have a clue where to start and trawling the internet has turned up nothing. I have two print queues per printer device, let's say we have "printer1" and "printer1d" where printer1d will automatically produce a duplex print. My default printer will be "printer1" and what I want my code to do is:

    1 take the name of the current default printer and add the letter 'd' to it so that "printer1d" becomes the current printer;
    2 print the current document;
    3 revert to the true default printer, i.e., "printer1".

    I hope that makes sense, and I hope even more that it is achievable!

    Thanks, Violet

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Change printer name for one print job (VB 6.3)

    Try this:

    Sub PrintDuplex()
    Dim strPrinter As String

    On Error GoTo ErrHandler

    ' Get currently active printer
    strPrinter = Application.ActivePrinter
    ' Set printer to duplex printer
    Application.ActivePrinter = strPrinter & "d"
    ' Print active document
    ActiveDocument.PrintOut

    ExitHandler:
    On Error Resume Next
    ' Restore original printer
    Application.ActivePrinter = strPrinter
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

    You may want to check at the beginning whether the name of the active printer already ends in "d".

  3. #3
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Change printer name for one print job (VB 6.3)

    Hi Hans,

    Thanks for that. Have tried it out but it didn't work - I failed to mention, however, that the printer queues are network queues - would that be a problem do you think?

    Violet

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Change printer name for one print job (VB 6.3)

    Does this work? If not, we'd have to know the exact names of the printers as they appear in the Print dialog.
    <code>
    Sub PrintDuplex()
    Dim strOldPrinter As String
    Dim strNewPrinter As String
    Dim intPos As Integer

    On Error GoTo ErrHandler

    ' Get currently active printer
    strOldPrinter = Application.ActivePrinter

    ' Assemble name of duplex printer
    intPos = InStr(strOldPrinter, " on ")
    strNewPrinter = Left(strOldPrinter, intPos - 1) & "d" & _
    Mid(strOldPrinter, intPos)

    ' Set printer to duplex printer
    Application.ActivePrinter = strNewPrinter
    ' Print active document
    ActiveDocument.PrintOut

    ExitHandler:
    On Error Resume Next
    ' Restore original printer
    Application.ActivePrinter = strOldPrinter
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub</code>

  5. #5
    2 Star Lounger
    Join Date
    Jun 2002
    Posts
    122
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Change printer name for one print job (VB 6.3)

    Hans you are my hero, that worked perfectly! What I'd do without you I don't know ; )

    Have a great weekend,

    Violet

Posting Permissions

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