Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I write a macro for OpenOffice writer, which get the words/characters that I selected with mouse an emphasis mark like dot over the words/characters?

I tried to record macro, but failed.

I hope someone here can help me


I am trying to write a macro for OpenOffice Writer and LibreOffice Writer. This macro will add a toolbar in Writer, similar to the Chinese punctuation toolbar in the Chinese version of MS Word. The buttons of the toolbar are Chinese punctuation marks. One of the button will be the emphasis mark used in simplified Chinese in China. The emphasis mark is a dot under the Chinese character that is emphasized when the text direction is horizontal, a dot on the right of the emphasized character when the text direction is vertical.

I do not know OpenOffice Basic or other languages used to write computer programs, but I know the macro recorder of the Writer can record some codes which can be used to write the macro I need. And I keep googling to find more information and learn to write the macro. For most of the punctuation marks, the codes are simple.

For example, to inset a stop mark, the codes are:

rem U+3002
sub cp01
dim document   as object
dim dispatcher as object
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Text"
args1(0).Value = "。"
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args1())
end sub

But the macro recorder of the LibreOffice 3.4 failed to record a workable macro for the emphasis mark. Actually the Writer closed unexpectedly as soon as I change the emphasis mark from "(Without)" to "Dot" in the Font Effects of the Character Dialog Box of the Writer. I was forced to download and install OpenOffice.org 3.3 and 3.4.

The macro recorder of the OpenOffice.org 3.3 also cannot record, but the one of the 3.4 did it. The macro is:

sub Test20120206_1
rem --------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem -------------------------------
dispatcher.executeDispatch(document, ".uno:EmphasisMark", "", 0, Array())
end sub

This macro do not work.

share|improve this question
    
Are you looking to create special characters from another language, like ñ? Or are you writing something where you need to designate emphasis on a syllable? –  Raystafarian Feb 7 '12 at 13:01

1 Answer 1

I found web-page: http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t=21813

A macro by FJCC made me very happy because it is short and about how to apply a effect to selected characters, this could be what I need.

Doc = ThisComponent
Selections = Doc.CurrentSelection
FirstSelection = Selections.getByIndex(0)
TextString = FirstSelection.String
UCaseStr = UCase(TextString)
FirstSelection.String = UCaseStr

Then I recombined this code with the macros from MS Word, the Japanese and Pitonyak A. and found a workable one:

sub EmphasisMark
Doc = ThisComponent
Selections = Doc.CurrentSelection
FirstSelection = Selections.getByIndex(0)
  If  FirstSelection.CharEmphasis = com.sun.star.text.FontEmphasis.NONE Then
      FirstSelection.CharEmphasis = com.sun.star.text.FontEmphasis.DOT_BELOW
  Else
      FirstSelection.CharEmphasis = com.sun.star.text.FontEmphasis.NONE
  End If
end sub

This is what I need. Finally...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.