Running a macro when clicking in a Hyperlink in Writer

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
brunnerdan
Posts: 43
Joined: Tue Nov 29, 2011 12:41 am

Running a macro when clicking in a Hyperlink in Writer

Post by brunnerdan »

Is it possible (or how is it possible) to specify a macro that should be run when clicking on an URL (hyperlink) that is defined in a Writer document ?
OOO 3.3 on Solaris/Windows
User avatar
RoryOF
Moderator
Posts: 35237
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Running a macro when clicking in a Hyperlink in Writer

Post by RoryOF »

Do you wish to merely run a macro as the hyperlink, or to open a hyperlink to another file and run the macro on it?
Apache OpenOffice 4.1.16 on Xubuntu 24.04.4 LTS
brunnerdan
Posts: 43
Joined: Tue Nov 29, 2011 12:41 am

Re: Running a macro when clicking in a Hyperlink in Writer

Post by brunnerdan »

I would like to run the macro as a hyperlink. The idea is that the macro get the "description" of the hyperlink and executes a macro taking the description as parameter.
OOO 3.3 on Solaris/Windows
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Running a macro when clicking in a Hyperlink in Writer

Post by Villeroy »

This URL: vnd.sun.star.script:MyLibrary.MyModule.MyRoutine?language=Basic&location=document&MyExtraArg=AnythingElse
calls the following macro MyLibrary.MyModule.MyRoutine with the full URL string as argument:

Code: Select all

Sub MyRoutine(sURL$)
print sURL 'prints the above URL
myArg = getArgumentFromURL(sURL,"MyExtraArg")
print myArg 'prints AnythingElse
End Sub
See also: http://user.services.openoffice.org/en/ ... rl#p214392 where you can copy function getArgumentFromURL.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
brunnerdan
Posts: 43
Joined: Tue Nov 29, 2011 12:41 am

Re: Running a macro when clicking in a Hyperlink in Writer

Post by brunnerdan »

Thanks for this feature that I didin't know but is not exactly what I need.

I try to give some more explanation. Lets say that I add a description in a writer document that points to a website (for example Oracle = description, URL = http://www.oracle.com). When I open the writer document and I <crtrl>+<mouseclic> on the Oracle, I open the website of Oracle in a webrowser. My wish would be able to define a specific macro that is called if Iwhen I make a <simpleclic> on Oracle.

I hope that my explanation is clear enough.
OOO 3.3 on Solaris/Windows
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Running a macro when clicking in a Hyperlink in Writer

Post by Villeroy »

I think you can not have what you want easily. Hyperlinks pointing to Oracle.com point to nothing but Oracle.com. Anything else would be a security flaw.
This is the best I can get with some copied Basic code:
RedirectHyperlink.ods
(19.61 KiB) Downloaded 544 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply