| View previous topic :: View next topic |
| Author |
Message |
dragan Newbie

Joined: 29 Dec 2005 Posts: 1
|
Posted: Thu Dec 29, 2005 2:42 am Post subject: How to open and print OpenOffice document with VisualBasic? |
|
|
How to open and print OpenOffice document with VisualBasic?
I used same code to open a document (like template) than to replace some text in it and then to print it out.
Using the
oDoc.Print
or the
CallByName oDoc, "print", VbMethod, MakePropertyValue("Copies", 2)
didn't work.
Run-time error '438':
Object doesn't support this property or method
occured.
Please help me as soon as you can.
Here is the code
Sub PrintSome()
Dim oSM, oDesk, oDoc, oText, oCursor As Object 'OOo objects
Dim OpenParam(1) As Object 'Parameters to open the doc
Dim SaveParam(1) As Object 'Parameters to save the doc
Dim PrintParam(1) As Object
Set oSM = CreateObject("com.sun.star.ServiceManager")
Set oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
Set OpenParam(0) = MakePropertyValue("Hidden", True) ' Open the file hidden
Set oDoc = oDesk.loadComponentFromURL(ConvertToUrl(App.Path & "\Test.sxw"), "_blank", 0, OpenParam())
Set oText = oDoc.GetText
Set oCursor = oText.createTextCursor
'***** Replace part
Dim str1 As String, str2 As String
Dim oReplace As Object
str1 = "first"
str2 = "second"
Set oReplace = oDoc.createReplaceDescriptor()
oReplace.SearchCaseSensitive = True
oReplace.SearchString = str1
oReplace.ReplaceString = str2
oDoc.ReplaceAll oReplace
'******
oDoc.Print
CallByName oDoc, "print", VbMethod, MakePropertyValue("Copies", 2)
oDoc.Close (False)
Set oDesk = Nothing
Set oSM = Nothing
Set oDoc = Nothing
Set oText = Nothing
Set oCursor = Nothing
End Sub
'
'Converts a Ms Windows local pathname in URL (RFC 1738)
'Todo : UNC pathnames, more character conversions
'
Public Function ConvertToUrl(strFile) As String
strFile = Replace(strFile, "\", "/")
strFile = Replace(strFile, ":", "|")
strFile = Replace(strFile, " ", "%20")
strFile = "file:///" + strFile
ConvertToUrl = strFile
End Function
Function MakePropertyValue(cName, uValue) As Object
Dim oPropertyValue As Object
Dim oSM As Object
Set oSM = CreateObject("com.sun.star.ServiceManager")
Set oPropertyValue = oSM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
oPropertyValue.Name = cName
oPropertyValue.Value = uValue
Set MakePropertyValue = oPropertyValue
End Function
'
'A simple shortcut to create a service
'
Public Function CreateUnoService(strServiceName) As Object
Dim oServiceManager As Object
Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
Set CreateUnoService = oServiceManager.createInstance(strServiceName)
End Function |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
donaldo Newbie

Joined: 27 Feb 2006 Posts: 3
|
Posted: Mon Feb 27, 2006 12:56 am Post subject: |
|
|
Hi dragan,
I found, that the VB6-IDE has a problem with the Print-keyword on other, not clearly defined, objects. In case you use
Dim oDoc As Objects
you will get this error by the IDE of VB6.
I found a workaround using
| Code: | With oDoc
.Print
End With |
So the error was avoided.
Donald |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|