[Solved] Does OO Calc Macros allow Private Sub Macros?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
alf50
Posts: 129
Joined: Sun Jun 13, 2010 2:55 pm

[Solved] Does OO Calc Macros allow Private Sub Macros?

Post by alf50 »

There are times when I do not want the user to view or run Macros that I call from other subroutines. For example, when the order of running certain macros can damage your spread sheet. Does OO Support Private Subs? If so, How?
Last edited by alf50 on Mon Nov 26, 2012 12:17 am, edited 1 time in total.
OpenOffice 4.1.14 on Mac Catalina(10.15.7), RasPi4B (TwisterOS-8/2023update) & MS Wnds10
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Does OO Calc Macros allow Private Sub Macros?

Post by Zizi64 »

I think:
The OOo Basic uses of the concept of Private SUB.
This means that the sub is only valid inside of the current Module.

The Modules can be hidden, but they everyone can display again.
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.
tgkprog
Posts: 2
Joined: Fri Mar 16, 2012 5:29 pm

Re: Does OO Calc Macros allow Private Sub Macros?

Post by tgkprog »

i checked and can still see sub's (functions) that are private in the list of macros. how can i add this to the wish list?

Code: Select all

Private Sub doInnerWork
	MsgBox "do p"
End Sub
above is a tests sub, when i open the macros dialog in the tools menu (Calc) I can see it.

What I would like is that a Sub marked private can be called by other functions in the same module but not appear in the run macros list
Attachments
run macro (private sub shows up)
run macro (private sub shows up)
OpenOffice 3.2.1 (9502) Win 7 SP2 http://sel2in.com
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Does OO Calc Macros allow Private Sub Macros?

Post by Villeroy »

Use Python which is mature, comprehensible, object oriented, easy to learn. It lets you define macro objects to be exposed.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
B Marcelly
Volunteer
Posts: 1160
Joined: Mon Oct 08, 2007 1:26 am
Location: France, Paris area

Re: Does OO Calc Macros allow Private Sub Macros?

Post by B Marcelly »

Hi,
tgkprog wrote:What I would like is that a Sub marked private can be called by other functions in the same module but not appear in the run macros list
OpenOffice Basic ignores the Private term before a Sub. All Sub's are Public.
But OpenOffice Basic uses the library concept. By default macros are stored in the library "Standard".
  • Create a new library in the Basic Macro Organizer. Make sure you have chosen your document as Location.
  • After creation you can specify a password.
  • Put your secret macros in this library.
You may call these macros from a macro in the Standard library, provided the protected library has previously be loaded.

Code: Select all

BasicLibraries.loadLibrary("Library1") ' loading Library1
When the ordinary user opens the document he/she cannot see the content of the password protected library. Test yourself by reload of the document.

Warning
Basic Functions created for Calc formulas must reside in the Standard library. But from a Function in the Standard library you can load the protected library and call your secret function.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
eezacque
Posts: 5
Joined: Mon Jan 07, 2019 7:35 pm

Re: Does OO Calc Macros allow Private Sub Macros?

Post by eezacque »

B Marcelly wrote:Hi,
tgkprog wrote:What I would like is that a Sub marked private can be called by other functions in the same module but not appear in the run macros list
OpenOffice Basic ignores the Private term before a Sub. All Sub's are Public.
But OpenOffice Basic uses the library concept. By default macros are stored in the library "Standard".
  • Create a new library in the Basic Macro Organizer. Make sure you have chosen your document as Location.
  • After creation you can specify a password.
  • Put your secret macros in this library.
You may call these macros from a macro in the Standard library, provided the protected library has previously be loaded.

Code: Select all

BasicLibraries.loadLibrary("Library1") ' loading Library1
When the ordinary user opens the document he/she cannot see the content of the password protected library. Test yourself by reload of the document.

Warning
Basic Functions created for Calc formulas must reside in the Standard library. But from a Function in the Standard library you can load the protected library and call your secret function.
Tried this but it doesn't seem to be working: the password-protected library is accessible, as any other library.

(developing a macro in Writer instead of Calc, I don't think the idea is different?)
LibreOffice 6.0.7.3 on Ubuntu 18.04.1
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Does OO Calc Macros allow Private Sub Macros?

Post by JeJe »

You could put the subs in a module called InternalUseOnly or something else that discourages the user from looking there.

And stop the macro doing anything if its run from a menu as a parameter won't be provided:

Code: Select all

Sub test(optional key)
if ismissing(key) =true then exit sub
msgbox 4
End Sub
Edit:

Another roundabout approach would be to customise the Tools menu with your own replacement or supplementary "Macros" button that loads your own dialog or menu with just the macros you want the user to be able to run. The normal macros run dialog is VERY clunky anyway... you've got to find the library... then the module... then the sub... terrible...
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply