Ask Your Question
0

Writer macros to change style properties

asked 2017-10-31 08:35:20 +0200

JDługosz gravatar image

I want to write macros to change some of the properties of paragraph and character styles. In particular, highlight by changing the background color.

So I used the Macro Recorder and made the change, and saw that it recorded a call to dispatcher.executeDispatch with specific arguments. I had planned on seeing what the arguments were for changing and changing back, and then writing code to toggle the state.

    ⋮
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Param"
args1(0).Value = "InnerDialog"
args1(1).Name = "Family"
args1(1).Value = 1

dispatcher.executeDispatch(document, ".uno:EditStyle", "", 0, args1())

But I didn't get that far. Any attempt to run the macro crashes LibreOffice. I tried the Macro > Run menu, and I tried Run Basic from the code editor.

The empty Main macro that is already present does not crash (though it doesn't do anything). I see a library BBkode that presumably is used by the extension, and the extension works.

Furthermore, after running LibreOffice again, the macro is missing. I even tried making a new Library for my stuff, and it also is no longer present.

What can I do?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-10-31 17:14:52 +0200

Jim K gravatar image

The macro recorder creates dispatcher code, which is not so good. The following API code changes the background color of the paragraph style named MyStyle.

Sub ChangeParaStyle
    oFamilies = ThisComponent.StyleFamilies.getByName("ParagraphStyles")
    oStyle = oFamilies.getByName("MyStyle")
    oStyle.ParaBackColor = RGB(255,141,56)
End Sub

For more examples, see http://www.pitonyak.org/oo.php.

It also sounds like you are not sure how to set up and run macros. There is a tutorial at https://www.debugpoint.com/2014/09/wr....

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-10-31 08:35:20 +0200

Seen: 526 times

Last updated: Oct 31 '17