'
'Creates a sequence of com.sun.star.beans.PropertyValue s
'
Function MakePropertyValue(cName, uValue)' As Object
Dim oStruct, oServiceManager 'as Object
Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
Set oStruct = oServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
oStruct.Name = cName
oStruct.Value = uValue
Set MakePropertyValue = oStruct
End Function
'Converts a Ms Windows local pathname in URL (RFC 1738)
'Todo : UNC pathnames, more character conversions
'
Function ConvertToUrl(strFile) 'As String
strFile = Replace(strFile, "\", "/")
strFile = Replace(strFile, ":", "|")
strFile = Replace(strFile, " ", "%20")
strFile = "file:///" + strFile
ConvertToUrl = strFile
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
Function openDoc(sFile)
Rem
Rem Load an existing writer document, with opening parameters
Rem
Dim oSM, ODesk 'as Object 'root object from OOo API
Dim oDoc 'as Object 'The document to be opened
Dim OpenPar(1) 'As Object 'a Visual Basic array, with 3 elements
'sFile ="C:\oo\11.doc"
sFileURL = ConvertToUrl(sFile)
'Instanciate OOo : the first line is always required from Visual Basic for OOo
Set oSM = CreateObject("com.sun.star.ServiceManager")
Set oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
'We call the MakePropertyValue function, defined just before, to access the structure
Set OpenPar(0) = MakePropertyValue("ReadOnly", False)
' Set OpenPar(1) = MakePropertyValue("Password", "secret")
Set OpenPar(1) = MakePropertyValue("Hidden", False)
'Now we can call the OOo loadComponentFromURL method, giving it as
'fourth argument the result of our precedent MakePropertyValue call
Set oDoc = oDesk.loadComponentFromURL(sFileURL, "_blank", 0, OpenPar)
set openDoc = oDoc
End Function
'''''''''''''''
sFile ="C:\oo\11.doc"
sFile2 ="C:\oo\22.doc"
set oDoc = openDoc(sFile) ' открываем файл в который вставить
set oDoc2 = openDoc(sFile2) ' файл, содержащий текст вставки
Flag=True
set TextPointer = oDoc.GetText
set CursorPointer = TextPointer.CreateTextCursor
set BookmarksSupplier=oDoc.getBookmarks
set Bookmark=BookmarksSupplier.getByName("Zakl").getAnchor
Text = "hhhhhhhh"
'Bookmark.setString(Text)
Bookmark.setString(oDoc2)