Outlook VB Script Printer

Joel Allen
Joel Allen used Ask the Experts™
on
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

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

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".

Commented:
Try

Next 

Open in new window


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

Next prtLoop

Open in new window

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
I'm a little confused.  The last line does have Next prtLoop.
Commented:
Yes, I said, change that to just

Next

Open in new window

Author

Commented:
Thank you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial