[Solved] Macro doesn't run until document reloaded

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
vyskol
Posts: 32
Joined: Thu Feb 19, 2009 10:13 pm

[Solved] Macro doesn't run until document reloaded

Post by vyskol »

I'm creating a new Calc document from a template file.

Code: Select all

	strURL = ConvertToUrl( SPREADSHEET_PATH & "InventoryWorksheet.ots" )
	objDoc = StarDesktop.loadComponentFromURL( strURL, "_blank", 0, dummy() )
Code then fills the spreadsheet with all the relevant data and saves.

Code: Select all

	strURL = ConvertToUrl( SPREADSHEET_PATH & Format$( Date(), "YYYYMMDD" ) & "inventory.ods" )
	objDoc.storeAsURL(strURL, dummy())
The custom toolbar is there, with the buttons linked to macros contained within the spreadsheet. However, clicking on them does nothing.
Until I close the new spreadsheet and reload it. Then the buttons/macros work fine. This is the case regardless of how I have the macro security settings set. I've even tried closing the new spreadsheet and then reopening it through code, but the macros still don't work. Not until the spreadsheet is manually opened by the user.
Last edited by vyskol on Sun Apr 12, 2009 9:48 pm, edited 1 time in total.
OOo 3.0.X on Ms Windows XP
User avatar
squenson
Volunteer
Posts: 1885
Joined: Wed Jan 30, 2008 9:21 pm
Location: Lausanne, Switzerland

Re: Macro doesn't run until document reloaded

Post by squenson »

Where did you store this macro: MyMacro or a document? What is the library name? Is the library loaded when you try using macro names?
LibreOffice 4.2.3.3. on Ubuntu 14.04
vyskol
Posts: 32
Joined: Thu Feb 19, 2009 10:13 pm

Re: Macro doesn't run until document reloaded

Post by vyskol »

The toolbar macros are stored within the document.
I guess they're not being loaded when the file is loaded through code... It's not loaded when I try using macro names.

Until I close the file and reopen it. Then all the macros work perfectly.
(Manually. The macros still don't work when closing and reopening the file through code.)
OOo 3.0.X on Ms Windows XP
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Macro doesn't run until document reloaded

Post by B Marcelly »

Hi,
If you want to execute macros in a document loaded by software you need to explicitly allow macro execution when loading it.

Code: Select all

Dim props(0) As New com.sun.star.beans.PropertyValue
props(0).Name = "MacroExecutionMode"
props(0).Value = com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE_NO_WARN

objDoc = StarDesktop.loadComponentFromURL( strURL, "_blank", 0, props() )
______
Bernard
vyskol
Posts: 32
Joined: Thu Feb 19, 2009 10:13 pm

Re: [solved] Macro doesn't run until document reloaded

Post by vyskol »

Thank you. :)
OOo 3.0.X on Ms Windows XP
Post Reply