Sub MainVS1()
Dim oBook As Object
Dim cUrl As String
Dim oServiceManager As Object
Dim oCalcDoc As Object
Dim aNoArgs()
Dim oSheet As Object
Dim oCells As Object
'создаем новый ServiceManager
Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
Set oCalcDoc = oServiceManager.createInstance("com.sun.star.frame.Desktop")
'открываем файл
cUrl = ConvertToUrl("\\IVUSHKA-TWO\DB_Zakaz\Realiz\Реализация" + ".ods")
Set oBook = oCalcDoc.loadComponentFromURL(cUrl, "_blank", 0, aNoArgs())
Dim disp As Object
Set disp = CreateUnoService("com.sun.star.frame.DispatchHelper")
Set oSheet = oBook.getSheets().getByIndex(0)
Set oCell = oSheet.getCellByPosition(0, 4)
Call oBook.CurrentController.Select(oCell)
Call disp.executeDispatch(oCalcDoc, ".uno:RecalcPivotTable", "", 0, Array())
End Sub
Public Function ConvertToUrl(strFile) As String
'конвертирует путь MS Windows в URL (RFC 1738)
strFile = Replace(strFile, "\", "/")
strFile = Replace(strFile, ":", "|")
strFile = Replace(strFile, " ", "%20")
strFile = "file:///" + strFile
ConvertToUrl = strFile
End Function
Public Function CreateUnoService(strServiceName) As Object
'Создание объекта UnoService
Dim oServiceManager As Object
Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
Set CreateUnoService = oServiceManager.createInstance(strServiceName)
End Function
|