(Solved) Modify character properties within Writer selection using Basic macro

In a Writer Basic macro, I am trying to increase font size of every character within the selection. This subroutine works well, but operates over the whole document, not just the selection. Can I limit the range to the selected text?

Sub FontUp 'Increase size of each character in selection by 1.

Dim oSel as Object, oTC as Object, oParEnum as Object, oPar as Object,

Dim oSecEnum as Object, oSec as Object, CharHeight As Long

oSel = ThisComponent.CurrentSelection.getByIndex(0)    'get the current selection
oTC = ThisComponent.Text.createTextCursorByRange(oSel) ' and span it with a cursor

rem Scan the cursor range for chunks of given text size.

oParEnum = oTC.Text.createEnumeration()
  Do While oParEnum.hasMoreElements()
    oPar = oParEnum.nextElement()

    If oPar.supportsService("com.sun.star.text.Paragraph") Then
      oSecEnum = oPar.createEnumeration()
      Do While oSecEnum.hasMoreElements()
        oSec = oSecEnum.nextElement()
        If oSec.TextPortionType = "Text" Then
          CharHeight = oSec.CharHeight
          oSec.CharHeight = CharHeight - 1
        End If
      Loop
    End If

  Loop

End Sub

I now have a solution to this problem provided on the OOo Forum by Bernard and B Marcelly.

http://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=60896

Thanks to both!

Bernard = B Marcelly :wink: