[Solved] Running macro when a hyperlink is pressed

Creating a macro - Writing a Script - Using the API
Post Reply
Redfantic
Posts: 6
Joined: Mon Sep 19, 2011 5:26 pm

[Solved] Running macro when a hyperlink is pressed

Post by Redfantic »

Hi Guys,

I'm looking to run a macro when a hyperlink is pressed in Open Office CALC. Is there a way to go about doing that?
Last edited by Redfantic on Tue Sep 20, 2011 4:34 pm, edited 1 time in total.
OpenOffice 3.3 on Windows 7
User avatar
Villeroy
Volunteer
Posts: 30885
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Running macro when a hyperlink is pressed

Post by Villeroy »

Formula to call Basic routine Standard.Module1.Main stored in this document passing a userdefined argument from cell A1:

Code: Select all

=HYPERLINK("vnd.sun.script:Standard.Module1.Main?language=Basic&location=document&MyArgument="&A1)

Code: Select all

Sub Main(sURL)
Const cArgName = "MyArgument"
myVar = getArgumentFromURL(sURL,cArgName)

End Sub

REM returns "" if no value was found for name.
Function getArgumentFromURL(sURL$,sName$) as String
on error goto exitErr:
Dim iStart%, i%, l%, sArgs$, a()
	iStart = instr(sURL, "?")
	l = len(sName)
	if (iStart = 0) or (l = 0) then exit function
	' sArgs behind "?":
	sArgs = mid(sURL, iStart +1)
	a() = split(sArgs, "&")
	for i = 0 to uBound(a())
		' not case sensitive:
		if instr(1, a(i), sName &"=", 1) = 1 then
			getArgumentFromURL = mid(a(i), l +2)
			exit for
		endif
	next
exitErr:
' return ""
End Function
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
Redfantic
Posts: 6
Joined: Mon Sep 19, 2011 5:26 pm

Re: Running macro when a hyperlink is pressed

Post by Redfantic »

I'm Sorry, I don't quite understand the code as I'm New to VB programming.

Is it possible to explain how the code works?
OpenOffice 3.3 on Windows 7
User avatar
Villeroy
Volunteer
Posts: 30885
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Running macro when a hyperlink is pressed

Post by Villeroy »

A forum can not teach you how to program.
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
Redfantic
Posts: 6
Joined: Mon Sep 19, 2011 5:26 pm

Re: Running macro when a hyperlink is pressed

Post by Redfantic »

Alright. Thanks for the help though :)
OpenOffice 3.3 on Windows 7
User avatar
Villeroy
Volunteer
Posts: 30885
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Running macro when a hyperlink is pressed

Post by Villeroy »

Anyhow, the hyperlink vnd.sun.script:Standard.Module1.Main?language=Basic&location=document
calls Basic macro Standard.Module1.Main of this document. location=application calls the macro in the global name space.
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