I often need to transform a plain text DOI to a hyperlink in writer. I can do it manually but I think a macro can save me some time.
Starting with the DOI as a selection, here is the best I could do:
sub Main
rem #----------------------------------------------------------------------
rem # define variables
dim document as object
dim dispatcher as object
rem #----------------------------------------------------------------------
rem # get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem #----------------------------------------------------------------------
rem # Copy DOI
dim doi(0) as new com.sun.star.beans.PropertyValue
dispatcher.executeDispatch(document, ".uno:Copy", "", 0, doi())
rem #----------------------------------------------------------------------
rem # Create hyperlink properties
dim hyperlink(4) as new com.sun.star.beans.PropertyValue
hyperlink(0).Name = "Hyperlink.Text"
hyperlink(0).Value = doi(0).Value
hyperlink(1).Name = "Hyperlink.URL"
hyperlink(1).Value = "http://dx.doi.org/" & doi(0).Value
hyperlink(2).Name = "Hyperlink.Target"
hyperlink(2).Value = ""
hyperlink(3).Name = "Hyperlink.Name"
hyperlink(3).Value = ""
hyperlink(4).Name = "Hyperlink.Type"
hyperlink(4).Value = 1
rem #----------------------------------------------------------------------
rem # Apply hyperlink properties
dispatcher.executeDispatch(document, ".uno:SetHyperlink", "", 0, hyperlink())
end sub
I get an active hyperlink, but its URL is only “http://dx.doi.org/”. The text contains the DOI, though.
How can I get the DOI appended to the URL?