We help IT Professionals succeed at work.

Outlook VB Script Printer

108 Views
Last Modified: 2018-12-11
Hello,

I have an Outlook custom form that uses VB Script to print a label.  This works fine.  IT has since migrated Office to a virtual server.  Because of this, the issue is that every time you log on to the server, the printer name changes dynamically, like "DYMO (redirected 99)".  The "99" is the part that changes.

Is it possible to call out a printer that contains the name "DYMO" in it?  Here is the code that I use.

Sub CommandButtonShipLabelUSPS_Click()

On Error Resume Next

Dim strCurrentPrinter

      Set objDoc2 = GetWordDocLabel("\\fireglass.com\drawing$\Jobs\Task_Templates\Ship-Ship Label USPS.dot")
          Call FillFieldsShipLabel(objDoc2)
          objDoc2.Application.Options.PrintBackground = False
          objDoc2.Application.DisplayAlerts = False
          'objDoc2.Application.ActiveDocument.AttachedTemplate = "Normal"
          'objDoc2.Application.ActiveDocument.PageSetup.Orientation = 1

if Item.UserProperties("PrintHold") = True then
        Set objDoc2 = Nothing
        Set strCurrentPrinter = Nothing
        Set objWord2 = Nothing
      Exit Sub
end if

          strCurrentPrinter = objDoc2.Application.ActivePrinter ' store the current active printer
          objDoc2.Application.ActivePrinter = "DYMO" ' change to another printer

bjDoc2.PrintOut ' print the active sheet
objDoc2.Application.ActivePrinter = strCurrentPrinter

      objDoc2.Application.DisplayAlerts = True
          objDoc2.Application.Options.PrintBackground = True

objDoc2.Close wdDoNotSaveChanges
objWord2.Quit wdDoNotSaveChanges

      Set objDoc2 = Nothing
        Set strCurrentPrinter = Nothing
        Set objWord2 = Nothing

End Sub

Thank you,
Joel
Comment
Watch Question

KimputerIT Manager
CERTIFIED EXPERT

Commented:
Either fix the code for everyone (or link user to his own shared dymo, works only in LAN environment), or enumerate all, and select based on detecting Dymo in the string  (requires every computer that logs in to NOT have ghost/hidden/inactive Dymo printers in their list):

 For Each prtLoop In Application.Printers 
            With prtLoop 
                strMsg = strMsg _ 
                    & "Device name: " & .DeviceName & vbCrLf _ 
                    & "Driver name: " & .DriverName & vbCrLf _ 
                    & "Port: " & .Port & vbCrLf & vbCrLf 
            End With 
        Next prtLoop 

Open in new window


Example code only, insert an if statement detecting Dymo and setting the printer or other variable.

Author

Commented:
Thank you.  I think we're getting close.  I get "Expected end of statement" error on the last line "Next prtLoop".
KimputerIT Manager
CERTIFIED EXPERT

Commented:
Try

Next 

Open in new window


instead of what I put there (mistake on my side)

Next prtLoop

Open in new window

Author

Commented:
I'm a little confused.  The last line does have Next prtLoop.
IT Manager
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Thank you.