Link to home
Start Free TrialLog in
Avatar of Joel Allen
Joel Allen

asked on

Outlook VB Script Printer


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("\\\drawing$\Jobs\Task_Templates\Ship-Ship Label")
          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,
Avatar of Kimputer

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.
Avatar of Joel Allen


Thank you.  I think we're getting close.  I get "Expected end of statement" error on the last line "Next prtLoop".


Open in new window

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

Next prtLoop

Open in new window

I'm a little confused.  The last line does have Next prtLoop.
Avatar of Kimputer

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you.