Ask Your Question

writer macro for extending selection from Table to paragraph before and after table [closed]

asked 2020-01-03 11:51:57 +0100

torreone gravatar image

updated 2020-08-05 00:11:49 +0100

Alex Kemp gravatar image

I use this code for selecting textTable in writer. How modify this macro for extending selection from this selected table to previous paragraph before table and next paragraph after table ? Using oVC.goDown(n, true) or oVC.goUp(n,true) not work.

  oVC= d.currentController.viewCursor
  oCell=t.getCellByPosition (0,0) 
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by torreone
close date 2020-01-03 13:51:02.048797

1 Answer

Sort by » oldest newest most voted

answered 2020-01-03 12:52:31 +0100

updated 2020-01-03 12:56:23 +0100

Try this code:

DefObj o
Sub ExtendTableSelection
  Dim oDoc, oTab, oCell, oVC, oEnum, oPar, oPrevPar, oNextPar
  oDoc = ThisComponent
  oTab = oDoc.getTextTables().getByName("Tabella1")
  oCell = oTab.getCellByPosition(0, 0) 
  oVC = oDoc.getCurrentController().getViewCursor()
  oVC.gotoRange(oCell, false)
  oVC.goUp(1, false) ' exit table and operate in its parent text '
  oEnum = oVC.getText().createEnumeration()
  ' Iterate through paragraphs (and tables) looking for the required table '
  ' Remember previous paragraph for the selection '
  Do While oEnum.hasMoreElements()
    oPar = oEnum.nextElement()
    If EqualUnoObjects(oPar, oTab) Then ' Found! '
      If Not (oPrevPar Is Nothing) And oEnum.hasMoreElements() Then
        oNextPar = oEnum.nextElement()
        oVC.gotoRange(oPrevPar, false)
        oVC.gotoRange(oNextPar, true)
      End If
      Exit Do
    End If
    oPrevPar = oPar
End Sub
edit flag offensive delete link more


In addition to working great, you use solutions that I didn't know about and that can help me in other cases.

Thank you very much

torreone gravatar imagetorreone ( 2020-01-03 13:50:01 +0100 )edit

Please, if the answer solves the question click ✔.

m.a.riosv gravatar imagem.a.riosv ( 2020-01-03 15:30:24 +0100 )edit

Question Tools

1 follower


Asked: 2020-01-03 11:51:57 +0100

Seen: 55 times

Last updated: Jan 03 '20