Page 1 of 1

[Solved] Editing Style Properties through VB Macro

PostPosted: Fri Feb 26, 2010 2:25 pm
by vit123
Hi Friends! I'm a newbie to OOo Writer (using v3.2 on WinXP)
I tried everything to record a VB macro that might let me change a preset paragraph (or character) style:
I've got some text set in "myStyle" style which is set "black", I don't mean to change directly the text style or property, but I wish to change "myStyle"'s colour property to "red" through a macro (I'll link to a button; another button will link a similar Macro doing the contrary: a fast way to switch view)
Recording a Macro I get this code:
...
args1(0).Name = "Param"
args1(0).Value = "myStyle"
args1(1).Name = "Family"
args1(1).Value = 1
dispatcher.executeDispatch(document, ".uno:EditStyle", "", 0, args1())
...
but running it just allows me to open the Edit Style Dialog Window, it seems it cannot record any setting..
I guess I need to complete the code manually by mysef somehow:
May you help me to get a sample VB code to change properties of a named Style through a Macro?

Thanks anybody for your time,
Vittorio (Italy)

Re: Editing Style Properties through VB Macro

PostPosted: Fri Feb 26, 2010 3:18 pm
by Villeroy
You've got to program utilizing the UNO API. Dispatches from the macro recorder do not help.

Re: Editing Style Properties through VB Macro

PostPosted: Fri Feb 26, 2010 4:03 pm
by vit123
You've got to program utilizing the UNO API

yes, I feared that, please could you post here any raw code (e.g.for editing a "paragraph style property") as an example I can start from?
I would greatly appreciate
Thanks again,
V.

Re: Editing Style Properties through VB Macro

PostPosted: Fri Feb 26, 2010 4:11 pm
by Villeroy
http://www.oooforum.org/forum/search.phtml enter "stylefamilies" and get 163 results.
This forum has another 40 hits.

Re: Editing Style Properties through VB Macro

PostPosted: Fri Feb 26, 2010 6:25 pm
by vit123
Many THANKS to Villeroy for the useful link and the "magic" little word to search (it was just what I missed)!
I would suggest to anyone interested also:
- http://wiki.services.openoffice.org/wik ... nformation (great reference link list, particularly the ODT manual http://www.pitonyak.org/AndrewMacro.odt)
- http://api.openoffice.org/docs/common/r ... ttomBorder (for official detail reference)
Finally I wish to feed this forum posting my own new-born solution to the above mentioned matter:
Code: Select all   Expand viewCollapse view
sub Stampa
   Dim oStileCar,oStilePar
   oStileCar=thisComponent.StyleFamilies.getByName("CharacterStyles").getByName("VitCar")
   oStilePar=thisComponent.StyleFamilies.getByName("ParagraphStyles").getByName("VitStile")
   dim bordo as New com.sun.star.table.BorderLine
   If oStileCar.CharColor=13421772 Then rem STAMPA
      oStileCar.CharColor=16777215
      bordo.Color=0
      bordo.OuterLineWidth=0
   Else rem NO STAMPA
      oStileCar.CharColor=13421772
      bordo.Color=15132390
      bordo.OuterLineWidth=2
   End If
   oStilePar.BottomBorder=bordo
rem Print  oStilePar.BottomBorder.Color
rem 13421772 GRIGIO CHIARO
rem 16777215 BIANCO
rem 15132390 GRIGIO CHIARISSIMO
rem 0 NERO
end sub

it does EXACTLY the switching I meant!
P.S. Just arrived to OOo, but it really looks GREAT

My Best Regards and thanks once again,
Vittorio (Italy)

Re: [Solved] Editing Style Properties through VB Macro

PostPosted: Mon Sep 05, 2011 2:43 pm
by ivants
Hi
Please help me to write little macro in OpenOffice Basic, because I know just how to use macros recorder, not to programming it.
I'm just need change paragraph justification in style "MyBasic" to both border through macro.
Thanks, and sorry for my english.

Re: [Solved] Editing Style Properties through VB Macro

PostPosted: Mon Sep 05, 2011 4:42 pm
by Hagar Delest
Look at the Macro forum, there is a sticky with links to documentation. Or search for a similar topic with a code snippet.