hiding macro coding

N

Nisha

I usually send my files/templates to clients and I don't
want them to look/enter into my VBA coding. How can I do
that. I know to add password but I saw one of our clients
template where in the macro edit button was deactivated.
How's that done.

Any idea???

Thanks
 
H

Howard Kaikow

The most secure way is to use VB 6 to automate your Word code and distribute
VB DLLs with a minimal amount of code in the Word template.
 
J

Jezebel

Write your code as a VB DLL, then add that as a reference to your VBA.
You'll still need a little bit of VBA to call the functions in the DLL.

The macro Edit options is not enabled if the macro itself is not editable:
in a locked project, or in an add-in that is not actually open -- the
situations in which clicking on the project in VBA gives you the message
'Project is locked or unviewable'.
 
J

JB

Howard said:
The most secure way is to use VB 6 to automate your Word code and distribute
VB DLLs with a minimal amount of code in the Word template.
Hi Howard,

I'm interested in how to do this could you give me some info please or
point me to a link?
I have masses of code in VBA and it's very slow running from word macros
not to mention the mess it's in right now (this would give me reason to
tidy :) )

Cheers

J
 
J

JB

Jezebel said:
Write your code as a VB DLL, then add that as a reference to your VBA.
You'll still need a little bit of VBA to call the functions in the DLL.

The macro Edit options is not enabled if the macro itself is not editable:
in a locked project, or in an add-in that is not actually open -- the
situations in which clicking on the project in VBA gives you the message
'Project is locked or unviewable'.
Hi Jezebel,
Do you have any examples you could give me of calling the dll functions
from VBA?
J
 
J

Jonathan West

Hi Jezebel,
Do you have any examples you could give me of calling the dll functions
from VBA?

Hi JB,

Once you have an ActiveX DLL referenced from your project, you call it
exactly as if it was a class module within your project.

Take a look here for an example which uses the ActiveX DLL dsofile.dll,
which you can download from Microsoft. The template you can download from
this article has its code open so you can see how it all works.

Getting access to the Document Properties of a Word file
http://word.mvps.org/FAQs/MacrosVBA/DSOFile.htm
 
M

macropod

Hi Nisha,

You can restrict access to code in various modules by protecting them with a
password. The following code prevents someone from pressing the ALT F8 keys
to view/run the various subroutines. You put this sub in a file that you
want to protect. Then, if your user presses Alt+F8 or goes to
Tools|Macros|Macros... all they will get is a message box that says
disabled.

Sub ToolsMacro()
MsgBox "Disabled"
End Sub

Basically, this hijacks the built-in ToolsMacro Command.

You might also consider keeping the user from seeing the macros in the first
place, rather than taking away their ability to use the macro dialog.
Although you can't grey out the Edit button for macros that are in a file,
you can keep them appearing in the list of available macros. A few ways to
do that:
· Make them into Subs that take arguments (or Functions for that matter).
You can even do this using dummy arguments.
· Make them Private rather than Public Subs (only callable by other Subs in
the same Module).
· Put an "Option Private Module" declaration at the top of any code Module
housing Subs you don't want the user to see in the Macros list. These Subs
will be callable by any other sub in the same project, but not by any sub in
any other project.

Another approach would be to use an environment variable in the macro like:
If Environ("Username")<>Yourname Then Exit Sub
Although users could see the macro, this would effectively stop anyone
except you using it.

Yet another solution is to force the user to enter a password before the
macro is run.

Cheers
 
J

Jonathan West

macropod said:
Hi Nisha,

You can restrict access to code in various modules by protecting them with a
password. The following code prevents someone from pressing the ALT F8 keys
to view/run the various subroutines. You put this sub in a file that you
want to protect. Then, if your user presses Alt+F8 or goes to
Tools|Macros|Macros... all they will get is a message box that says
disabled.

Sub ToolsMacro()
MsgBox "Disabled"
End Sub

Basically, this hijacks the built-in ToolsMacro Command.

This can be got round very easily, it is not a security feature.
You might also consider keeping the user from seeing the macros in the first
place, rather than taking away their ability to use the macro dialog.
Although you can't grey out the Edit button for macros that are in a file,

Of course you can. If the macros are in a template loaded as an add-in
rather than in the template attached to the current document, then the edit
button is greyed out. For more on distributing macros in an add-in, take a
look at this article

Distributing macros to other users
http://word.mvps.org/FAQs/MacrosVBA/DistributeMacros.htm

you can keep them appearing in the list of available macros. A few ways to
do that:
· Make them into Subs that take arguments (or Functions for that matter).
You can even do this using dummy arguments.
· Make them Private rather than Public Subs (only callable by other Subs in
the same Module).
· Put an "Option Private Module" declaration at the top of any code Module
housing Subs you don't want the user to see in the Macros list. These Subs
will be callable by any other sub in the same project, but not by any sub in
any other project.

Well I never! I learned something new today. I had never come across Option
Private Module. That might have some uses. Thanks!
Another approach would be to use an environment variable in the macro like:
If Environ("Username")<>Yourname Then Exit Sub
Although users could see the macro, this would effectively stop anyone
except you using it.

Those are some interesting ideas, but it seems that aren't addressing the
original question, which was how to prevent *editing* of the macros rather
than stopping them being run.
 
J

JB

Jonathan said:
Hi JB,

Once you have an ActiveX DLL referenced from your project, you call it
exactly as if it was a class module within your project.

Take a look here for an example which uses the ActiveX DLL dsofile.dll,
which you can download from Microsoft. The template you can download from
this article has its code open so you can see how it all works.

Getting access to the Document Properties of a Word file
http://word.mvps.org/FAQs/MacrosVBA/DSOFile.htm
Thanks Jonathan,
This looks quite good.

J
 

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