How to call a macro given as string?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Toxitom
Posts: 1
Joined: Wed Jun 18, 2008 1:44 pm

How to call a macro given as string?

Post by Toxitom »

Hey,

my question is, how to call in Basic a macro, when I get only the Name as a string?

For example: I do have 3 macros, lets call then "macro1", "macro2" and "macro3".
Now I create an appliation string (array), which will include the Name of the macros to call. Now - haw can I call the Macro directly?

OK, I can use a "select Case" struture and can do a string-comparison, but is there a direct way?

Something like:

Code: Select all

sub Start
   aListe = array("Macro1", "Macro3", "Macro2")
   Startmacro(aListe)
end sub

sub startmacro(aListe)
   call (aListe(1))  ??????????????
end sub

sub macro1
  ...
end sub

sub maro2
  ...
end sub

sub macro3
  ...
end sub
Any suggestions?

thanks
Thomas
OOo 2.4.X on MS Windows Vista
TerryE
Volunteer
Posts: 1402
Joined: Sat Oct 06, 2007 10:13 pm
Location: UK

Re: How to call a macro given as string?

Post by TerryE »

google "call macro site:wiki.services.OpenOffice.org"; third topic
Ubuntu 11.04-x64 + LibreOffice 3 and MS free except the boss's Notebook which runs XP + OOo 3.3.
pitonyak
Volunteer
Posts: 186
Joined: Sun Oct 07, 2007 9:13 pm
Location: Columbus, Ohio, USA

Re: How to call a macro given as string?

Post by pitonyak »

You need the full path to the macro

Code: Select all

Sub RunGlobalNamedMacro
  oDisp = createUnoService("com.sun.star.frame.DispatchHelper")
  sMacroURL = "macro:///Gimmicks.AutoText.Main"
  oDisp.executeDispatch(StarDesktop, sMacroURL, "", 0, Array())
End Sub
Andrew Pitonyak
http://www.pitonyak.org/oo.php
LO and AOO on Fedora
Post Reply