Writer macro for extending selection from Table to paragraph before and after table

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.

  d=thisComponent
  t=d.textTables.getByName("Tabella1")
  oVC= d.currentController.viewCursor
  oCell=t.getCellByPosition (0,0) 
  oVC.gotoRange(oCell,false)         
  oVC.gotoEnd(True)

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
  Loop
End Sub

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

Please, if the answer solves the question click :heavy_check_mark:.