I have a macro in calc that used to work in 7.3.2, but gives different results since I installed 24.2.3.
The macro clears the selected cell, inserts a hyperlink, then goes back to that cell, inserts a Paragraph_Break (hard return) and insets a second hyperlink. All used to work great.
This is the first I’ve run the macro since updating to 24.2.3. Now it clears the cell, inserts the first hyperlink, but when it goes back to the cell to add the second, the Paragraph_Break gets added, but the second hyperlink overwrites the first hyperlink and the break is after the only hyperlink remaining.
If I put a break point anywhere in the debug window, say the very first line of code that defines the sub, then continue the macro and let it finish, it works fine. But if I don’t pause it in the debug, it doesn’t work right. Seems like it’s a focus thing, but like I said, it used to work fine. Here’s the piece of code that actually inserts the hyperlinks and the break:
Sub InsertHyperlink(LinkURL as String, LabelText as String, IsFirst as Boolean)
dim oFrame as Object
dim dispatcher as Object
dim txt as Object
dim tc as Object
oFrame = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
if IsFirst Then ' Before inserting the first hyperlink, clear the selected cell
dispatcher.executeDispatch(oFrame, ".uno:ClearContents", "", 0, Array())
Else
' Edit the selected cell to insert a paragraph break before inserting the next hyperlink
txt = ThisComponent.CurrentController.Selection.text
tc = txt.CreateTextCursorByRange(txt.end) ' Create a text cursor at the end of the text in the cell
'tc.collapsetoend ' Move text cursor to the end of the text
' Insert the hard return at text cursor position
txt.insertControlCharacter(tc, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, True)
end if
dim HypData(4) as new com.sun.star.beans.PropertyValue
' Data for hyperlink
HypData(0).Name = "Hyperlink.Text"
HypData(0).Value = LabelText
HypData(1).Name = "Hyperlink.URL"
HypData(1).Value = ConvertToURL(LinkURL) ' Link needs to be in URL format
HypData(2).Name = "Hyperlink.Target"
HypData(2).Value = ""
HypData(3).Name = "Hyperlink.Name"
HypData(3).Value = ""
HypData(4).Name = "Hyperlink.Type"
HypData(4).Value = 1
dispatcher.executeDispatch(oFrame, ".uno:SetHyperlink", "", 0, HypData())
End Sub
Can anyone show me the error of my ways? I’d like to blame something that’s changed, but my track record isn’t good, so if I’ve done something stupid, let me know.