Select Text Table Columns

Hopefully a simple question, but I cannot seem to find an answer in the documentation or online:

I want to be able to select particular rows/columns within Writer document text tables.

In theory the macro should look something like this:

sub test

Doc = ThisComponent
Col = Doc.getTextTables(0).getColumns.getbyindex(3)
Doc.CurrentController.Select(Col)	

end sub

However, I am currently getting a BASIC runtime error:

Property or method not found: getColumns.

(Same goes for ‘getRows’)

The command seems to work if I create a table from scratch, but will not work on existing tables??

Thanks in advance!

Hi

I would do something like this:

option explicit

sub PysSelectCol

dim oDoc as object, oTable as object, oCell as object
dim oCursor as object, oFrame as object, oDispatcher as object

oDoc = ThisComponent

oTable = oDoc.getTextTables.GetByIndex(0)
oCell = oTable.getCellByName("D1")

oCursor = oCell.createTextCursor
oDoc.currentController.Select(oCursor)
oFrame = oDoc.CurrentController.Frame

oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oDispatcher.executeDispatch(oFrame, ".uno:EntireColumn", "", 0, Array())

end sub

See

Regards

Or - without DispatchHelper - you can select range of cells:

Sub SelectColumnTextTable(Optional nCol As Long)
Dim oTextTable As Variant
Dim nLastColumn As Long
Dim nLastRow As Long
Dim oCellRangeByPosition As Variant
Dim oCurrentController As Variant
	oTextTable = ThisComponent.getTextTables().getByIndex(0)
	nLastColumn = oTextTable.getColumns().getCount() - 1
	If IsMissing(nCol) Then nCol = nLastColumn
	If (nCol<0) or (nCol>nLastColumn) Then Exit Sub
	nLastRow = oTextTable.getRows().getCount() - 1
	
	oCellRangeByPosition = oTextTable.getCellRangeByPosition(nCol, 0, nCol, nLastRow)
	ThisComponent.getCurrentController().select(oCellRangeByPosition)
End Sub