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

Creating a macro - Writing a Script - Using the API

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

Postby alf50 » Tue Jun 29, 2010 2:03 pm

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.5 on Mac El Capitan(10.11.6) and MS Windows10
alf50
 
Posts: 97
Joined: Sun Jun 13, 2010 2:55 pm

Re: Does OO Calc Macros allow Private Sub Macros?

Postby Zizi64 » Thu Jul 01, 2010 7:36 pm

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; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.3.4; AOO4.1.6
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: 8662
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Does OO Calc Macros allow Private Sub Macros?

Postby tgkprog » Fri Nov 02, 2012 1:43 pm

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
Attachments
macro_private.jpg
run macro (private sub shows up)
OpenOffice 3.2.1 (9502) Win 7 SP2 http://sel2in.com
tgkprog
 
Posts: 2
Joined: Fri Mar 16, 2012 5:29 pm

Re: Does OO Calc Macros allow Private Sub Macros?

Postby Villeroy » Fri Nov 02, 2012 1:57 pm

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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27577
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Does OO Calc Macros allow Private Sub Macros?

Postby B Marcelly » Fri Nov 02, 2012 5:48 pm

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.
Bernard

OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
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?

Postby eezacque » Wed Jan 09, 2019 8:12 pm

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?)
LibreOffice 6.0.7.3 on Ubuntu 18.04.1
eezacque
 
Posts: 5
Joined: Mon Jan 07, 2019 7:35 pm

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

Postby JeJe » Wed Jan 09, 2019 8:40 pm

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...
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 700
Joined: Wed Mar 09, 2016 2:40 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 7 guests