OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to open and print OpenOffice document with VisualBasic?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
dragan
Newbie
Newbie


Joined: 29 Dec 2005
Posts: 1

PostPosted: Thu Dec 29, 2005 2:42 am    Post subject: How to open and print OpenOffice document with VisualBasic? Reply with quote

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
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Thu Dec 29, 2005 7:46 am    Post subject: Reply with quote

See :
A tutorial for Programming OpenOffice.org with Visual Basic http://www.oooforum.org/forum/viewtopic.phtml?t=11854&highlight=
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
donaldo
Newbie
Newbie


Joined: 27 Feb 2006
Posts: 3

PostPosted: Mon Feb 27, 2006 12:56 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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