[Solved] Open Basic IDE via macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Gerhard1234
Posts: 2
Joined: Thu Jan 29, 2015 12:27 pm

[Solved] Open Basic IDE via macro

Post by Gerhard1234 »

I am searching for the Basic command to open up the macro editor and to load a specific module in it.
----------------------------------------
The way to transfer the arguments to the BasicIDEAppear service seem to have changed. Especially the document name
needs to be given in a differen way, than it was before.

Following is the correct code, verified with LibreOffice Writer 4.3.5.2 the currently stable Version from http://www.libreoffice.org

Code: Select all

   dim aArgs(5) as New com.sun.star.beans.PropertyValue
   aArgs(0).Name="Document": aArgs(0).Value=ThisComponent.GetURL
   aArgs(1).Name="LibName": aArgs(1).Value="Standard"
   aArgs(2).Name="Name": aArgs(2).Value="Module1"
   aArgs(3).Name="Line": aArgs(3).Value=10
   aArgs(4).Name="Type": aArgs(4).Value="Module" 'may be Dialog or Module
   oFrame = CreateUnoService("com.sun.star.frame.Frame")
   oDispatchHelper = createUnoService("com.sun.star.frame.DispatchHelper")
   oTemp = oDispatchHelper.ExecuteDispatch(oFrame, ".uno:BasicIDEAppear" ,"" ,0 ,aArgs())
This code will open the Basic IDE, load the Standard library from the current document, open Module1 and
position the blinking cursor in line #10 to start editing there. Just that there is no misunderstanding: "The order
of the PropertyValues in the array do not make a difference." Following is an attachment document to
demonstrate this solution.
BasicIDEAppear.odt
Libreoffice writer document to demonstrate solution to open the Basic maro editor and display code in this document.
(32.83 KiB) Downloaded 235 times
Thanks alot, to all envolved!

P.S. I leave the other tipps in here for further reading.
----------------------------------------
Reading the answers, following is my conclusion:

The correct command to open up the IDE seems to be the following

Code: Select all

oTemp = oDispatchHelper.ExecuteDispatch(oFrame, ".uno:BasicIDEAppear" ,"" ,0 ,aOptions())
but for some reason this seems not to work any more.

There is a workaround to generate an error in a subroutine inside of the module to open, which opens the IDE
and a message box with an errormessage. The following code is an example for that.

Code: Select all

Sub OpenIDE
	thisComponent.makeError
End Sub
----------------------------------------
Thanks for you help!
Last edited by Gerhard1234 on Tue Feb 03, 2015 11:41 am, edited 4 times in total.
OOO 3.5 and OOO 4.3
on Debian Wheezy
User avatar
Zizi64
Volunteer
Posts: 11386
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Open Basic IDE via macro

Post by Zizi64 »

Do you want to load a Library into the memory?

Code: Select all


if GlobalScope.BasicLibraries.hasByName("Name_of_Library") then
	if  Not GlobalScope.BasicLibraries.isLibraryLoaded("Name_of_Library") Then
		GlobalScope.BasicLibraries.LoadLibrary("Name_of_Library")
	End if 
End if
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: Open Basic IDE via macro

Post by hanya »

See: viewtopic.php?f=20&t=14849
"Document" option can be URL for a document if you want to open some macro stored in target document.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
hanya
Volunteer
Posts: 885
Joined: Fri Nov 23, 2007 9:27 am
Location: Japan

Re: [Workaround] Open Basic IDE via macro

Post by hanya »

Gerhard1234 wrote:The correct command to open up the IDE seems to be the following

Code: Select all

oTemp = oDispatchHelper.ExecuteDispatch(oFrame, ".uno:BasicIDEAppear" ,"" ,0 ,aOptions())
but for some reason this seems not to work any more.
As I wrote:
"Document" option can be URL for a document if you want to open some macro stored in target document.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
Gerhard1234
Posts: 2
Joined: Thu Jan 29, 2015 12:27 pm

Re: [Workaround] Open Basic IDE via macro

Post by Gerhard1234 »

hanya wrote:
Gerhard1234 wrote:The correct command to open up the IDE seems to be the following

Code: Select all

oTemp = oDispatchHelper.ExecuteDispatch(oFrame, ".uno:BasicIDEAppear" ,"" ,0 ,aOptions())
but for some reason this seems not to work any more.
As I wrote:
"Document" option can be URL for a document if you want to open some macro stored in target document.
Sorry, I did not get your hint about the URL-format of the document name ...
OOO 3.5 and OOO 4.3
on Debian Wheezy
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: [Solved] Open Basic IDE via macro

Post by B Marcelly »

It means that you can simplify the code given in the above link.
Here I open the IDE in Module1 of library Standard of the document which runs the macro.
I have modified the presentation for easier reading.

Code: Select all

    sub sOpenMacroEditor
       dim aOptions(4) as New com.sun.star.beans.PropertyValue
       aOptions(0).Name="LibName"
       aOptions(0).Value="Standard"  ' Name of library
       aOptions(1).Name="Name"
       aOptions(1).Value="Module1"   ' Name from Module or Dialog
       aOptions(2).Name="Line"
       aOptions(2).Value=440 ' Position the cursor at this line number in the module
       aOptions(3).Name="Type"
       aOptions(3).Value="Module"   ' Module or Dialog
       aOptions(4).Name="Document"
       aOptions(4).Value= ThisComponent.URL  ' indicate the URL of the document
       oFrame = CreateUnoService("com.sun.star.frame.Frame")
       oDispatchHelper = createUnoService("com.sun.star.frame.DispatchHelper")
       oTemp = oDispatchHelper.ExecuteDispatch(oFrame, ".uno:BasicIDEAppear" ,"" ,0 ,aOptions())
    end sub
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
Post Reply