[Solved] Running macro when a hyperlink is pressed

Creating a macro - Writing a Script - Using the API

[Solved] Running macro when a hyperlink is pressed

Postby Redfantic » Tue Sep 20, 2011 3:22 pm

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
Redfantic
 
Posts: 6
Joined: Mon Sep 19, 2011 5:26 pm

Re: Running macro when a hyperlink is pressed

Postby Villeroy » Tue Sep 20, 2011 3:40 pm

Formula to call Basic routine Standard.Module1.Main stored in this document passing a userdefined argument from cell A1:
Code: Select all   Expand viewCollapse view
=HYPERLINK("vnd.sun.script:Standard.Module1.Main?language=Basic&location=document&MyArgument="&A1)


Code: Select all   Expand viewCollapse view
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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28664
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Running macro when a hyperlink is pressed

Postby Redfantic » Tue Sep 20, 2011 3:56 pm

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
Redfantic
 
Posts: 6
Joined: Mon Sep 19, 2011 5:26 pm

Re: Running macro when a hyperlink is pressed

Postby Villeroy » Tue Sep 20, 2011 4:05 pm

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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28664
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Running macro when a hyperlink is pressed

Postby Redfantic » Tue Sep 20, 2011 4:34 pm

Alright. Thanks for the help though :)
OpenOffice 3.3 on Windows 7
Redfantic
 
Posts: 6
Joined: Mon Sep 19, 2011 5:26 pm

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

Postby Villeroy » Tue Sep 20, 2011 5:58 pm

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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28664
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 3 guests