CreateObject("com.sun.star.ServiceManager") Fails

System:
Ubuntu 20.04.3 LTS x64 Bit
LibreOffice Version: 6.4.7.2 Build ID: 1:6.4.7-0ubuntu0.20.04.1
Java - Oracle
Java version “17.0.1” 2021-10-19 LTS
Java™ SE Runtime Environment (build 17.0.1+12-LTS-39)
Java HotSpot™ 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)


Problem: Macro fails on… .
Set oSM = CreateObject(“com.sun.star.ServiceManager”)

Note: using/ run from LibreOffice API


Error Message:
“Error Creating Object.
Module Cannot Be Loaded; invalid format.”


Sub Borders2

Dim oSM As Object, SavePath As String
Dim oDesk As Object 'Objects from the API
Dim oDoc As Object 'Objects from the API
Dim oSheet As Object 'Objects from the API
Dim oItalic As Object
Dim arg()
Dim I As Integer, J As Integer

Set oSM = CreateObject(“com.sun.star.ServiceManager”)
Set oDesk = oSM.CreateInstance(“com.sun.star.frame.Desktop”)
Set oDoc = oDesk.loadComponentFromURL(“private:factory/scalc”, “_blank”, 0, arg())
Set oSheet = oDoc.getSheets().getByIndex(0)

.
.
.

End Sub

Thank you, provides an alternative and appears to work.

But, why does original CreateObject ( " … ." ) work on a Windows system ? Should it not work on both platforms ?

No, CreateObject only work in the program language that implement such as VBA, VB.net, etc…

CreateObject not is part of LibreOffice Basic

To clarify, CreateObject() is part of LibreOffice BASIC, but it can’t be used to create a ServiceManager, that already exists when LibreOffice runs BASIC. Creating a ServiceManager object and thus LibreOffice instance works only from said languages.

CreateObject not is part of LibreOffice Basic

Run this:

Option Explicit
Type address
    Name1 As String
    City As String
End Type

Function doUnitTest as String
    ' CREATEOBJECT
    If ( IsObject( CreateObject("address") ) = False ) Then
        doUnitTest = "FAIL"
    Else
        doUnitTest = "OK"
    End If
End Function

Sub Main
	print doUnitTest()
End Sub

Perhaps this will help:

The original Code, with CreateObject(), run from Libre Office 5.4 API, works just fine.

Running on Windows Vista, Service Pack 2.

Hopefully that ?kinda? helps ?

ok, your right

https://help.libreoffice.org/7.3/en-US/text/sbasic/shared/03132400.html?&DbPAR=WRITER&System=UNIX

Use

 Set oSm=GetProcessServiceManager()

Look:

https://wiki.documentfoundation.org/Macros/Basic/Documents#New_documents