Printing from WSH/VBScript

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
tahoar
Posts: 1
Joined: Mon Jan 26, 2009 12:59 pm

Printing from WSH/VBScript

Post by tahoar »

I'm trying to print files from Windows WSH/VBScript. I started with a working script that opens a file. I then recorded a macro (below) that prints files directly to the default pinter and modified the code for VBScript, and added it to my Print-It.vbs that opens the file. It seems like it should work, but get the following Windows Script Handler/VBScript error:

Script: c:\scripts\Print-It.vbs
Line: 19
Char: 1
Error: Type mismatch: 'executeDispatch'
Code: 800A000D
Source: Microsoft VBScript runtime error

Seems like a simple-enough requirement... print a file from the COM/OLE-Automation interface without user intervention. Is there a way to fix this or better way to accomplish the same thing?

Tom


***** working Openoffice.org Basic code from record macro function in OpenOffice.org Writer *****
Sub PrintDirectly()
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:PrintDefault", "", 0, Array())
End Sub

***** Begin Print-It.vbs *****
Dim oServiceManager
Dim oDesktop
Dim oDoc
Dim oDispatchHelper
Dim mArgs(0)
Dim sURL

sURL = Replace(Wscript.Arguments(0), ":" , "|")
sURL = "file:///" & Replace(sURL, "\" , "/")

Set oServiceManager = WScript.CreateObject("com.sun.star.ServiceManager")
Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop")

Set mArgs(0) = MakePropertyValue("Hidden", False)
Set oDoc = oDesktop.loadComponentFromURL(sURL, "_blank", 0, mArgs)

set oDispatchHelper = oServiceManager.createInstance("com.sun.star.frame.DispatchHelper")
call oDispatchHelper.executeDispatch (oDoc, ".uno:PrintDefault", "", 0, mArgs)

oDoc.close(True)
Set oDispatchHelper = nothing
Set oDoc = nothing
Set oDesktop = nothing
Set oServiceManager = nothing

wscript.quit


Function MakePropertyValue(cName, uValue)
Dim oStruct
Set oStruct = oServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
oStruct.Name = cName
oStruct.Value = uValue
Set MakePropertyValue = oStruct
End Function

***** end Print-It.vbs *****
OOo 3.0.X on Ms Windows XP
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Printing from WSH/VBScript

Post by B Marcelly »

Hi,
Read and use VBx OOo tools. There is a tool dedicated to VBScript.
______
Bernard
Post Reply