-
Notifications
You must be signed in to change notification settings - Fork 2
/
basic_extras_SetCursorToCell.bas
41 lines (37 loc) · 2.98 KB
/
basic_extras_SetCursorToCell.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'--------------------------------------------------------------------------------------------------'
' SetCursorToCell '
'--------------------------------------------------------------------------------------------------'
' Sets cursor to a cell specified by a cell name or reference object. '
' GoToCell would've been a shorter name for this function but I found `Go` a bit confusing because '
' it has unclear meaning. '
' '
' Parameters: '
' '
' Cell As Variant '
' Reference to a range or cell (com.sun.star.table.XCellRange / com.sun.star.table.XCell) or a '
' string name ("B5","R1C1", etc). '
' '
' Examples: '
'--------------------------------------------------------------------------------------------------'
' '
' SetCursorToCell("B5") '
' SetCursorToCell("R1C1") '
' SetCursorToCell("$'Sheet.name.with.dots'.$G$9") '
' SetCursorToCell(ThisComponent.Sheets.getByIndex(0).getCellByPosition(6,4)) '
' '
'--------------------------------------------------------------------------------------------------'
' Feedback & Issues: '
' https://github.com/aa6/libreoffice_calc_basic_extras/issues '
'--------------------------------------------------------------------------------------------------'
Sub SetCursorToCell(Cell As Variant)
Dim args(0) As New com.sun.star.beans.PropertyValue
Dim dispatcher As Object
args(0).Name = "ToPoint"
If TypeName(Cell) = "String" Then
args(0).Value = Cell
Else
args(0).Value = IIf(TRUE,Cell,Cell).AbsoluteName ' `Object variable not set.` workaround. '
End If
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(ThisComponent.CurrentController.Frame, ".uno:GoToCell", "", 0, args())
End Sub