Numbered list macro

I need a simple macro to convert selected autonumbered list to simple text - numbers should appear as hand-written numbers afterwards.

I found such a macro for Word:

Sub AutoNumberToText()
   Selection.Range.ListFormat.ConvertNumbersToText
End Sub

but it does not work in LibreOffice. Any ideas?

Press F12 or go to Format → Lists → Numbered List.

The macro recorder (Tools → Macros → Record Macro with macro recording enabled under Tools → Options → Advanced) is often problematic, but it does well in this case.

document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "On"
args1(0).Value = false
dispatcher.executeDispatch(document, ".uno:DefaultNumbering", "", 0, args1())

A more complex numbering macro using com.sun.star.text.NumberingRules is given at [Solved] Starbasic Macro for bullets and numbering look (View topic) • Apache OpenOffice Community Forum.

EDIT:

Here is a macro to convert the selected numbered list to ordinary paragraphs with the label numbers.

Sub ConvertNumberedListToLabels
    oSel = ThisComponent.getCurrentController.getSelection()
    oSelEnd = oSel.getByIndex(0).getEnd()
    oCurs = ThisComponent.getText().createTextCursorByRange(oSelEnd)
    oCurs.gotoStartOfParagraph(False)
    While oCurs.NumberingIsNumber = True
        labelString = oCurs.ListLabelString
        oCurs.getText().insertString(oCurs, labelString & " ", False)
        oCurs.NumberingRules = None
        oCurs.gotoPreviousParagraph(False)
    Wend
End Sub

I tried to add the code you posted to the macros (enclosing it in sub MacroName - end sub). All it did was remove automatic numbering.

But what I need is different. I want the automatic numbering to be turned into normal numbers – as if I have entered them using keyboard.

See edited answer.

@jimk: the macro has some shortcomings:

  1. It stops when some paragraph in selection is not numbered;
  2. It does not handle elements with level higher than 1 in multilevel lists properly.

This should work in these cases:

Sub ConvertNumberedListToLabels
    oSel = ThisComponent.getCurrentController.getSelection()
    oSelEnd = oSel.getByIndex(0).getEnd()
    oCurs = ThisComponent.getText().createTextCursorByRange(oSelEnd)
    oCurs.gotoStartOfParagraph(False)
    Do
      If oCurs.NumberingIsNumber Then
        labelString = oCurs.ListLabelString
        oCurs.getText().insertString(oCurs, labelString & " ", False)
        While Not IsEmpty(oCurs.NumberingRules)
          oCurs.NumberingRules = None
        Wend
      End If
    Loop While oCurs.gotoPreviousParagraph(False)
End Sub

@mikekaganski: Okay, I believe you that it’s better. I’m a little surprised to see your comment though. I do not remember this question or writing this answer, and it doesn’t seem like there’s been much interest in it. Why take the time to make the code better?

… because I came across this when answering someone on some forum; and it inspired me to implement VBA’s ConvertNumbersToText (to be available in 7.1 :-))

Thank you for writing the code!

@mikekaganski: Glad to hear you found it useful. Thanks for implementing the new feature!