Search code examples
vbalibreofficelibreoffice-impress

Macro in LibreOffice to change the background of an Impress Slide to a solid black color


Looked all around and could not find it. Need a macro so that I can repeat it 695 times, on 695 different files I have. Documentation is kind of uneasy, or I am unlucky.

I could do it in Microsoft VBA as follows:

Sub VbaBlackies
    Dim oSl As Slide
    For Each oSl In ActivePresentation.Slides
        With oSl
            .FollowMasterBackground = msoFalse
            .DisplayMasterShapes = msoFalse
            With .background
                .Fill.ForeColor.RGB = RGB(0, 0, 0)
                .Fill.BackColor.RGB = RGB(0, 0, 0)
                End With
            End With
        Next oSl
End Sub

I am looking for something similar in LibreOffice BASIC. I could get started in the code this way:

Sub Main
Dim oDoc As Object
Dim oDPages As Object
Dim oDPage As Object
oDoc= ThisComponent
oDPages = oDoc.getDrawPAges()
For i=0 To oDPages.count()-1
    oDPage = oDPages.getByIndex(i)
    oDPage.Background = RGB(0,0,0)  'This does not work.
    'I have no idea on how to access the object's properties and alter them.
    Next i
End Sub

Any ideas, please?


Solution

  • What you are looking for is in Listing 15.1 of Andrew Pitonyak's macro document, an essential reference for macro programming.

    Sub ChangeBackground
        Dim oDoc as Object
        oDoc = ThisComponent
        Dim oDrawPages as Object, oDrawPage as Object
        oDrawPages = oDoc.getDrawPages()
        oDrawPage = oDrawPages.getByIndex(0)
        Dim oBackground as Object
        oBackground = oDoc.createInstance("com.sun.star.drawing.Background")
        oBackground.FillColor = RGB(250,0,0)
        oDrawPage.Background = oBackground
    End Sub
    

    API documentation is at https://www.openoffice.org/api/docs/common/ref/com/sun/star/drawing/Background.html.