Sorry if this has been addressed before, but I cannot find anything on the matter pertaining to Writer.
I am trying to create a macro in LO Basic, which will do a simple task: I select a piece of text in Writer, I have copied a URL (address string “http://www…”) in the clipboard, and the macro will paste the URL as a link in the selected text. Note: not replace text, just convert the selected text to a hyperlink and set the target URL to the one in the clipboard.
I’ve already tried multiple things I’ve found on-line, but nothing seems to work, especially in getting the selected text from Writer. I’ve tried “ThisComponent.GetCurrentSelection()” but I can’t find how to extract the selected text/string. Also, I cannot find how to inject the URL in a piece of text – well, apart from Ctrl-K, Ctrl-V which is what I want to avoid.
Here’s a snippet of code I’m using, but multiple errors crop up:
Sub PasteURLInSelection
Dim sel As Object, doc As Object, txt as String
doc = ThisComponent
sel = doc.getCurrentSelection()
REM print sel.getStart()
REM print sel.getString()
txt = getClipboardText()
print getClipboardText()
End Sub
The “getClipboardText()” subroutine is something I found and it works in returning the contents of the clipboard as plain text.
Any help would be most appreciated.