Hi,
I have a user that browses to an intranet pricelist (the page is print ready) My problem is that he needs to print various quantities of the page to various printer locations.
I thought I would try to whip up a script for him to save mouse clicks & time.
Here is what I have got from much googling.
As you can tell it should first find the existing default printer, set another printer, print x copies etc and then restore the original default printer.
Basically the Appactivate method always returns false whether IE is open or not.
I also looked at the ExecWB method but that seems to involve creating a new instance of IE.
Any help is very appreciated.
Peter.
Remember- It's nice to be important,
but it's important to be nice
I have a user that browses to an intranet pricelist (the page is print ready) My problem is that he needs to print various quantities of the page to various printer locations.
I thought I would try to whip up a script for him to save mouse clicks & time.
Here is what I have got from much googling.
Code:
Option Explicit
'[Determine the current default printer]***
'(works only on WinXP and newer versions of Windows)
Dim objWMIService, colPrinters, Iexplore
Dim objPrinter, strPreDefault
Set objWMIService = GetObject _
("winmgmts:\\" & "." & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery _
("Select * From Win32_Printer Where Default = TRUE")
For Each objPrinter in colPrinters
strPreDefault = objPrinter.Name
Next
'wscript.echo chr(34) & strPreDefault & chr(34) & " is the default
printer now"
'[Set the temporarily default printer]***
On Error Resume Next
Dim strLocal, objNetwork
strLocal = "Canon iR C3200 PCL5c"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.SetDefaultPrinter strLocal
Set objNetwork = Nothing
wscript.echo chr(34) & strLocal & chr(34) & " is the default printer
now"
Set WshShell = WScript.CreateObject("Wscript.Shell")
wshShell.AppActivate ("Internet Explorer")
If ret = False Then
Msgbox "Internet Explorer is not running."
WScript.Quit
end if
WScript.Sleep 2000
For copies = 1 to 2
WshShell.SendKeys "%^P"
WScript.Sleep 520
WshShell.SendKeys "{ENTER}"
WScript.sleep 10000
Next
'[Restore the previous default printer]***
On Error GoTo 0
Set objNetwork = CreateObject("WScript.Network")
objNetwork.SetDefaultPrinter strPreDefault
wscript.echo chr(34) & strPreDefault & chr(34) & " is the
default printer again"
Set objNetwork = Nothing
Wscript.quit 0
As you can tell it should first find the existing default printer, set another printer, print x copies etc and then restore the original default printer.
Basically the Appactivate method always returns false whether IE is open or not.
I also looked at the ExecWB method but that seems to involve creating a new instance of IE.
Any help is very appreciated.
Peter.
Remember- It's nice to be important,
but it's important to be nice