libreoffice-basic

LibreOffice BASIC runtime error: property or method not found: createInstance


Running BASIC code on LibreOffice (7.4.5.2) Impress on Ubuntu 20.04 LTS. I am getting BASIC runtime error: property or method not found: createInstance when i run:

REM  *****  BASIC  *****

Option Explicit
Sub CreateAIHistoryPresentation1()
    Dim oDoc As Object
    Dim oPresentation As Object
    Dim oSlide As Object
    Dim oShape As Object
    Dim oText As Object
    Dim oTitle As Object
    Dim oImage As Object
    Dim i As Integer
    Dim service01Name As String
    Dim objDoc As Object
    
    'objDoc.BasicLibraries.LoadLibrary("Tools")
    if Not BasicLibraries.isLibraryLoaded("Tools") Then
        BasicLibraries.loadLibrary("Tools")
    End if
    GlobalScope.BasicLibraries.LoadLibrary("Tools")
    
    ' Create a new presentation document
    oDoc = StarDesktop.LoadComponentFromURL("private:factory/simpress", "_blank", 0, Array())
    oPresentation = oDoc.getPresentation
    oPresentation.dbg_properties
    oPresentation.dbg_methods
    
    ' Page 1: Title Slide
    oSlide = oPresentation.createInstance("com.sun.star.presentation.Slide")

the method is apparently loaded ok

createInstance method

Any suggestions?


Solution

  • It's the document object that has that method, right? So oDoc.createInstance(). The presentation object is used to control the presentation, for example, starting and stopping the slide show.

    Anyway, here is some code to insert a new slide.

    oSlideList = oDoc.getDrawPages()
    oSlide = oSlideList.insertNewByIndex(oSlideList.Count)
    

    Related: https://stackoverflow.com/a/48408229/5100564.