Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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("")
dim args1(0) as new
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 3.3 and 3.4.

The macro recorder of the 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("")
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

I found web-page:

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 = Then
      FirstSelection.CharEmphasis =
      FirstSelection.CharEmphasis =
  End If
end sub

This is what I need. Finally...

share|improve this answer

Your Answer


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.