Page 1 of 1

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

PostPosted: Tue Jun 29, 2010 2:03 pm
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?

Re: Does OO Calc Macros allow Private Sub Macros?

PostPosted: Thu Jul 01, 2010 7:36 pm
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.

Re: Does OO Calc Macros allow Private Sub Macros?

PostPosted: Fri Nov 02, 2012 1:43 pm
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   Expand viewCollapse view
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

Re: Does OO Calc Macros allow Private Sub Macros?

PostPosted: Fri Nov 02, 2012 1:57 pm
by Villeroy
Use Python which is mature, comprehensible, object oriented, easy to learn. It lets you define macro objects to be exposed.

Re: Does OO Calc Macros allow Private Sub Macros?

PostPosted: Fri Nov 02, 2012 5:48 pm
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   Expand viewCollapse view
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.

Re: Does OO Calc Macros allow Private Sub Macros?

PostPosted: Wed Jan 09, 2019 8:12 pm
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   Expand viewCollapse view
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?)

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

PostPosted: Wed Jan 09, 2019 8:40 pm
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   Expand viewCollapse view
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...