Keeping the User away from the code

E

Edward Thrashcort

I am putting a code library together for a project I'm working on and I
wondered if this architecture may give me problems in the future...

I want my library module to be shareable with my other modules and forms but
invisible to a user who is Customising a Toolbar by adding a Macro.

I am therefore creating all the routines as Function calls rather than Sub's
I am not declaring them as Public.

Could this backfire on me?

Eddie
 
J

Jonathan West

Edward Thrashcort said:
I am putting a code library together for a project I'm working on and I
wondered if this architecture may give me problems in the future...

I want my library module to be shareable with my other modules and forms
but
invisible to a user who is Customising a Toolbar by adding a Macro.

I am therefore creating all the routines as Function calls rather than
Sub's
I am not declaring them as Public.

Could this backfire on me?

Eddie

If you write them as Private, then they can't be called from outside the
same module

Not putting any keyword before the Function keyword has the same effect as
declaring it as Public.

If you're not wanting to call the routines from outside the template, you
should be safe enough.

There an alternative technique that you could use instead. Include a dummy
optional parameter in the Sub declaration, like this

Sub DoStuff(Optional bDummy As Boolean)


Which you decide to do is entirely up to you. I've used both ways, and there
doesn't seem to be much between them.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
E

Edward Thrashcort

So if I make a function Private, it can still be called from another module
in the same template?
Sub DoStuff(Optional bDummy As Boolean)

I'm not sure what this does? Area you saying that the optional parameter
makes the sub invisible?

Eddie
 
J

Jonathan West

Edward Thrashcort said:
So if I make a function Private, it can still be called from another
module
in the same template?
No.


I'm not sure what this does? Area you saying that the optional parameter
makes the sub invisible?

Yes. It causes the sub no longer to appear on the list of macros in the
Tools, macro dialog. That list consists of routines that meet the following
criteria

1. They are Subs or Public Subs,
2. They are in a module rather than a class or UserForm,
3. They have no parameters.

Only routines meeting all three of those conditions appear on the list of
macros.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
O

old man

I would also suggest that you save the code (through right clicking on the
project name in the Project Explorer window then click on the Project
Proterties then click on the Protection tab and select "Lock Project for
Viewing" and enter a password.

The password can be broken but at least you are making it moderately
difficult to do so.

When you declare a routine as private other modules (even in the same
project) don't have access to it. But the routines in the same module do have
access to it.

This will work as long as x2 and x3 are in the same module but x3 cannot be
called from anywhere else:
Private Sub x3()
MsgBox "x3"
End Sub

Sub x1()
x3
End Sub

old man
 
E

Edward Thrashcort

You may be interested to know that "WordBasic.Call" ignores the "Private"
declaration of functions ans Subs in external modules!!!

Eddie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top