Revision 336637613362 () - Diff

Link to this snippet: https://friendpaste.com/1vJ7IguEWBfVakYkVCE5n3
Embed:
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
Sub TextToHyperlink()
selection = ThisComponent.CurrentSelection
Select Case (selection.ImplementationName)
Case "ScCellObj"
If (selection.String = "") Then
Exit Sub
End If
ReplaceHyperlink(selection)
Case "ScCellRangeObj"
RangeReplaceHyperlink(selection.RangeAddress)
Case "ScCellRangesObj"
For Each address In selection.RangeAddresses
RangeReplaceHyperlink(address)
Next
End Select
End Sub

Sub RangeReplaceHyperlink(ByVal address)
sheet = ThisComponent.Sheets(address.Sheet)
For x = address.StartColumn To address.EndColumn
For y = address.StartRow To address.EndRow
cell = sheet.getCellByPosition(x, y)
If (cell.String = "") Then
If (y = address.StartRow) Then
Exit Sub
Else
Exit For
End If
End If
ReplaceHyperlink(cell)
Next
Next
End Sub

Sub ReplaceHyperlink(ByVal cell)
hyperlink = ThisComponent.createInstance("com.sun.star.text.TextField.URL")
hyperlink.Representation = cell.String
hyperlink.URL = cell.String
cell.Text.insertTextContent(cell.createTextCursor(), hyperlink, True)
End Sub