We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

Writer macros to change style properties [closed]

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 reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-10-19 03:35:46.999798

1 Answer

Sort by » oldest newest most voted

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

Question Tools



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

Seen: 1,192 times

Last updated: Oct 31 '17