Hello,
A few weeks ago, I switched from Excel to LibreOffice Calc. So I’m rewriting my macro’s and until now, I didn’t have to much problems, but I found myself stuck on a macro to retrieve data from another workbook, specifiquely when trying to reach te cells of the other workbook. My original Excel-function, to open another workbook, looks like this:
Function GetWorkBook(ByVal myFileName As String) As Workbook
Dim XLApp As New Excel.Application, cFile As String
On Error GoTo Err
If Dir(myFileName) = vbNullString Then Exit Function
Set GetWorkBook = XLApp.Workbooks.Open(Filename:=myFileName, ReadOnly:=True)
Err:
End Function
My first attempt was to use this function as it is, using the “Option VBASupport 1” statement and surprisingly, it seemed to work. I received an object, but looking at it more closely, dissapointment came in. I couldn’t reach the different sheets in this (workbook?) object. The sheets collection gives me an array of strings, where I expected objects.
Next step was to try to write a LibreOffice equivalent, which resulted in this code:
Function GetAnotherDocument(Byval cFile as String) as Object
Dim ui as variant
If (Not GlobalScope.BasicLibraries.isLibraryLoaded(“ScriptForge”)) Then
GlobalScope.BasicLibraries.LoadLibrary(“ScriptForge”)
End If
Set ui = CreateScriptService(“UI”)
set GetAnotherDocument = ui.Opendocument(cFile, ReadOnly := True, macroexecution := 1)
End Function
Unfortunately, the result was the same. Also, the sheets collection keeps giving me an array of strings, not objects (?). So I still can’t reach the underlying cells, to retrieve values from. I’m afraid I don’t really understand why I’m not getting the right object.
What am I doing wrong?
(LibreOffice 7.5.9.2 on Windows 11)