Want workaround for "Enable macros?" prompt

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
azalea4va
Posts: 6
Joined: Wed Apr 10, 2019 10:57 pm

Want workaround for "Enable macros?" prompt

Post by azalea4va »

 Edit: Split from [Solved] Function with thisComponent.Sheets throws an error because that topic is solved so you need your own. Your situation may be different. Please do not post in another's topic unless you are helping to solve their problem for them. 

Thank goodness I found this old thread. I am in the same situation (9 years later). I moved my macros into "My Macros" because because I have spreadsheets all over the place in my file structure. Trying to keep up with making sure all the directories are Trusted to avoid "Enable Macros?" was impractical.

The interesting thing is after going through the sequence of errors messages when the spreadsheet loads, if I do a Ctrl-Shift-F9 to recalculate, everything works fine.

To me, this is clearly a bug. This dates back to 2013. Any updated information on the situation and and hopefully a workaround? (Another solution would be to be able to specify all files under a top-level directory are trusted, but I have not found a way to do that either, what I consider another glaring deficiency.)
Linux Mint
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Solved] Function with thisComponent.Sheets throws an err...

Post by Zizi64 »

___________________________________
Open Office 6.0.7.3 on ubuntu0.18.04.
That version is LibreOffice but not OpenOffice. Please fix your signature.
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.
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Want workaround for "Enable macros?" prompt

Post by Zizi64 »

To me, this is clearly a bug.
Absolutely not. It is a safety feature in the newer LibreOffice versions.
You will be warned when:
- Some macro code is embedded into the file
- Some macro calling commands is embedded into the file.
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.
azalea4va
Posts: 6
Joined: Wed Apr 10, 2019 10:57 pm

Re: Want workaround for "Enable macros?" prompt

Post by azalea4va »

Thank for the heads up on the signature. It must have been auto-generated years ago when I joined the forum.

I understand the safety parameters but this is a bug. One does not have to "Enable Macros" when a macro is in My Macros. That is one of the safety parameters. But it appears a macro stored in My Macros does not have access to some objects quickly enough depending on how the spreadsheet is opened.

If I open librecalc with the spreadsheet as a parameter, thisComponent.Sheets throws an error. But after initial start-up, I can do Cntrl-Shift-F9 and thisComponent.Sheets no longer throws an error. In addition, if I open Libreoffice without specifying a filename, then once libreoffice starts I goto File -> Open and open my file, again thisComponent.Sheets does not throw an error.

The only time an error gets throw is in that one situation. Unfortuneately, that situation is the most convenient way to access my spreadsheets.
Linux Mint
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Want workaround for "Enable macros?" prompt

Post by JeJe »

You could try a wait statement to give loading a chance.

Or instead of using thiscomponent a function like this to get the first spreadsheet component:

Code: Select all

sub test
msgbox getspreadsheetcomponent.title
end sub

function getspreadsheetcomponent
dim c,doc
on error resume next
c = stardesktop.components.createenumeration
do while c.hasmoreelement
doc = c.nextelement
if doc.SupportsService("com.sun.star.sheet.SpreadsheetDocument") then
getspreadsheetcomponent = doc
exit do
end if
loop
End function
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply