Macros to Change (or get the name of) Network Printers

I've been thinking I need to write more sophisticated macros to change network printers. I've got some macros that open the printer applet in the control panel, then use keystrokes to change default printers, but they aren't 100% reliable.

I'm wondering if anyone has some examples. I've found some on the Internet, but am having trouble translating them to Dragon's syntax.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

This should work: Sub

This should work:

Sub Main

On Error GoTo Err:
strprinter = Printer Name 'Enter your printer name
Set WshNetwork = CreateObject("Wscript.Network")
WshNetwork.SetDefaultPrinter strPrinter
MsgBox strprinter & " has been set as your default printer."

Exit Sub

Err:
MsgBox Err.Description

End Sub

To create a list of available printers:
(This may run very slow)

Sub Main

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")

For Each objPrinter In colPrinters
strPrinter = objPrinter.Name
MsgBox strprinter
Next

End Sub

http://www.microsoft.com/technet/scriptcenter/guide/sas_wsh_vchc.mspx?mf...

Works perfectly, thanks.

Works perfectly, thanks. Getting the correct printer name on a network is really the trick. Once you have that, the rest doesn't seem to be too hard.

New, but related issue: When

New, but related issue:

When I use this macro to print to a PDF printer on my machine, I am unable to send keystrokes to the dialog box. I would like to use the keystrokes to cause the dialog box to navigate to a predetermined holder on my hard drive. Unfortunately, the macro is unable to place the keystrokes in the dialogue box, and may end up being inserted into the document after the macro has run in the document is printed. Any suggestions. Here's the code:

Dim strprinter As String

Sub Main
On Error GoTo Err:

Select Case ListVar1
Case "to 36"
ActivePrinter = "\\svdcpps1.wilmerhale.com\DCP_11136E_H"
Case "to 36 to"
ActivePrinter = "\\svdcpps1.wilmerhale.com\DCP_11136E_H2"
Case "two-sided"
ActivePrinter = "\\svdcpps1.wilmerhale.com\DCP_11136E_H2"
Case "to 52"
ActivePrinter = "\\svdcpps1.wilmerhale.com\DCP_11152E_L"
Case "to 39"
ActivePrinter = "\\svdcpps1.wilmerhale.com\DCP_11139E_C"
Case "in color"
ActivePrinter = "\\svdcpps1.wilmerhale.com\DCP_11139E_C"
Case "to PDF"
ActivePrinter = "Adobe PDF"
Case "New York 31"
ActivePrinter = "\\svnyps1.wilmerhale.com\NYC_3141_L"

End Select

EngineControl.DragonBar.ShowMessage showmessageNoBeep, "Printing " & ListVar1

Wait 5

Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=False, PrintToFile:=False, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0

Wait .5

If ListVar1 = "to PDF" Then
Wait .3
SendSystemKeys "{Bksp}",1
SendSystemKeys "{Home}c:\iManage imports\+{End}+{Left 4}"
End If

ActivePrinter = "\\svdcpps1.wilmerhale.com\DCP_11152E_L"

Exit Sub

Err:
MsgBox Err.Description

End Sub

I'm not sure but it sounds

I'm not sure but it sounds like a locus of focus problem. Have you tried switching out and back to see if that pinpoints the locus of focus Smiling

(Yes, I did respond just so I could say "locus of focus" twice, but it is also a serious suggestion.)

Bruce

I don't think that is the

I don't think that is the problem. I have had problems in the past with Microsoft Word when trying to dictate into various dialog boxes.

To put it another way, I

To put it another way, I think your "locus of focus" hypothesis is hocus pocus and almost certainly bogus.

Looks like no hocus pocus to

Looks like no hocus pocus to loss of focus.

I think that is what is happening. When the Save PDF File to dialog box opens, focus shifts and the code stops until the dialog box closes.

If you try to record a similar macro in Word, everything records until the dialog box opens.

You might be able to edit your Acrobat Settings to select the output directory and prevent the dialog box from opening:

You might be able to do this with code by changing a registry entry:

I actually figured out how

I actually figured out how to change the default directory in the printer settings yesterday afternoon. The only problem is that it also seems to take away my ability to name the document, but I suppose that is a small price to pay.

This problem -- the inability to dictate into Word dialog boxes -- is a major annoyance!

Matt Chambers wrote: This

Matt Chambers wrote:

This problem -- the inability to dictate into Word dialog boxes -- is a major annoyance!

I agree, as an experiment- can you try turning off Active Acessability to see if this helps?

Yes, I did, and it makes no

Yes, I did, and it makes no difference.

There you go getting all

There you go getting all hokey-pokey again Smiling

Sorry, but both suggestions where the best I could do. Surely someone is going to help figure out how to help you out.

Bruce

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.




view recent posts