An example of how to revert the numbering styles for a paragraph to the default specified in the paragraph style. This was created since in OpenOffice.org 1.1 there is presently no standard option to revert number styles -- that is, once you've hand modified the number style, you'd be stuck with it forever. This macro provides that revert number style option.

' Reverts the number style applied to the paragraph style default.
' That is, each paragraph in the selection will have the number style set to the
' numbering style defined for the paragraph style of the paragraph.
Sub RevertNumberStyleSel
	oDoc = ThisComponent
	oText = oDoc.Text

	' Select all current selections as cursors, and expect that maybe nothing is selected
	Dim oCursors(), i%
	If Not CreateSelectedTextIterator( oDoc, oCursors()) Then 
		'Get Cursor at current location
		oViewCursor = oDoc.CurrentController.getViewCursor()
		oTextCursor = oText.createTextCursorByRange(oViewCursor.getStart())
		RevertNumberStyle( oDoc, oTextCursor )
	Else
		' THe sanity control is because there is an error condition I don't fully understand
		' that sometimes results in an infinite loop.  So rather we limit it to a fixed number
		' of possible paragraphs.
		sanity = 0
		For i% = LBound(oCursors()) To UBound(oCursors())
			oCurStart = oCursors(i%,0)
			oCurEnd = oCursors(i%,1 )
			Do
				RevertNumberStyle( oDoc, oCurStart )
				sanity = sanity+1
		    Loop Until ( Not oCurStart.gotoNextParagraph( False ) ) _
		    	 OR ( oText.compareRegionStarts( oCurStart, oCurEnd ) <= 0 ) _
		    	 OR ( sanity > 10000 )
		Next i%
	
		If Sanity > 10000 Then
			MsgBox "Sanity Control Reached"
		End If
	End If
	
End Sub

' Reverts the number style at the particular TextCursor
Sub RevertNumberStyle( oDoc as Object, oTextCursor as Object )
	' Get list of Paragraph Styles
	oStyleFamilies = oDoc.StyleFamilies
	oParaStyles = oStyleFamilies.getByName( "ParagraphStyles" )
  
  	' Get Style for current paragraph
	oParaStyle = oParaStyles.getByName( oTextCursor.paraStyleName )
	
	' Set current paragraph numbering style to one defined in ParaStyle
	oTextCursor.NumberingStyleName = oParaStyle.NumberingStyleName
End Sub

The following are the required support functions. They are taken / modified from Andrew Pitonyak's macro reference.


'******************************************************************
' The following are support functions, they aren't really part of
' the logic of the macro, but nonetheless are essential to their
' operation.  Thanks to Andrew Pitonyak
'******************************************************************

'******************************************************************
'Modified from Andrew Pitonyak <andrew@pitonyak.org>
'sPrompt : how to ask if should iterate over the entire text
'oCursors() : Has the return cursors
'Returns true if should iterate and false if should not
Function CreateSelectedTextIterator(oDoc As Object, oCursors()) As Boolean
  Dim oSelections As Object, oSel As Object, oText As Object
  Dim lSelCount As Long, lWhichSelection As Long
  Dim oLCursor As Object, oRCursor As Object

  CreateSelectedTextIterator = True
  oText = oDoc.Text
  If Not IsAnythingSelected(ThisComponent) Then
    oCursors = DimArray()
    CreateSelectedTextIterator = False
  Else
    oSelections = ThisComponent.getCurrentSelection()
    lSelCount = oSelections.getCount()
    oCursors = DimArray(lSelCount - 1, 1)
    For lWhichSelection = 0 To lSelCount - 1
      oSel = oSelections.getByIndex(lWhichSelection)
      'If I want to know if NO text is selected, I could
      'do the following:
      'oLCursor = oText.CreateTextCursorByRange(oSel)
      'If oLCursor.isCollapsed() Then ...
      oLCursor = GetLeftMostCursor(oSel, oText)
      oRCursor = GetRightMostCursor(oSel, oText)
      oCursors(lWhichSelection, 0) = oLCursor
      oCursors(lWhichSelection, 1) = oRCursor
    Next
  End If
End Function

'******************************************************************
'From Andrew Pitonyak <andrew@pitonyak.org>
Function IsAnythingSelected(oDoc As Object) As Boolean
  Dim oSelections As Object, oSel As Object, oText As Object, oCursor As Object
  IsAnythingSelected = False
  If IsNull(oDoc) Then Exit Function
  ' The current selection in the current controller. 
  'If there is no current controller, it returns NULL.
  oSelections = oDoc.getCurrentSelection()
  If IsNull(oSelections) Then Exit Function
  If oSelections.getCount() = 0 Then Exit Function
  If oSelections.getCount() > 1 Then 
    IsAnythingSelected = True
  Else
    oSel = oSelections.getByIndex(0)
    oCursor = oDoc.Text.CreateTextCursorByRange(oSel)
    If Not oCursor.IsCollapsed() Then IsAnythingSelected = True
  End If
End Function

'******************************************************************
'Author: Andrew Pitonyak
'email:   andrew@pitonyak.org
'oSelection is a text selection or cursor range
'oText is the text object
Function GetLeftMostCursor(oSel As Object, oText As Object) As Object
  Dim oRange As Object, oCursor As Object
  
  If oText.compareRegionStarts(oSel.getEnd(), oSel) >= 0 Then
    oRange = oSel.getEnd()
  Else
    oRange = oSel.getStart()
  End If
  oCursor = oText.CreateTextCursorByRange(oRange)
  oCursor.goRight(0, False)
  GetLeftMostCursor = oCursor
End Function

'******************************************************************
'Author: Andrew Pitonyak
'email:   andrew@pitonyak.org
'oSelection is a text selection or cursor range
'oText is the text object
Function GetRightMostCursor(oSel As Object, oText As Object) As Object
  Dim oRange As Object, oCursor As Object
  
  If oText.compareRegionStarts(oSel.getEnd(), oSel) >= 0 Then
    oRange = oSel.getStart()
  Else
    oRange = oSel.getEnd()
  End If
  oCursor = oText.CreateTextCursorByRange(oRange)
  oCursor.goLeft(0, False)
  GetRightMostCursor = oCursor
End Function