Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make Code invisible 1

Status
Not open for further replies.

moswitch

Technical User
Feb 26, 2007
40
US
Hey guys and Gals, how do I make my VBA code invisible to the end user? I don't want to show my code.

Thanks in advance.
 
Password protect your VBA project.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks, but I was hoping I could hide the code for one of my 9 modules, not all of them.
 
If your application is Excel you may consider an add-in (.xla)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
AFAIK, you can not hide anything at the module level.

If your application is Word, you may want to consider loading your code from a template, installed as a temporary Addin.

Say you put your code into a .Dot file - TestMe.dot. It does NOT have to be in any of the identified Word file locations. It can be anywhere.

In your document (or if you want, in your normal.dot, so it works for any document) put an instruction to load the template. The best place is in Document_Open.
Code:
Sub Document_Open()
   AddIns.Add FileName:="C:\Temp\Whatever\TestMe.dot", _
      Install:=True
End Sub
Now all the code etc. is available. However, the code modules are NOT. Trying to look at the Project will return an "Project unviewable." message.

With the exception of normal.dot, file code modules are not viewable unless the actual container file is open. HOWEVER, loaded as an Addin, the code itself is available (executable).

To unload it, say on Document close:
Code:
Sub Document_Close()
    AddIns("C:\Temp\Whatever\TestMe.dot").Delete
End Sub

I know of no way to selectively hide one module.

Gerry
My paintings and sculpture
 
Hi moswitch,

There are some simple ways to hide vba subs from users when they look in the macros dialogue box. Protecting a vba module has no effect on whether a user can see the sub's name in that dialogue box.

Perhaps the simplest waysto hide a vba sub is to add 'Option Private Module' to the top of the code module - doing so will hide all subs in that module.

To hide a single sub, you could add the word 'Private' before the sub name (ie change 'Sub MyCode()' to 'Private Sub MyCode()'). Another way is to add a dummy parameter (eg change 'Sub MyCode()' to 'Sub MyCode(Dummy as Boolean)'). A third way is to change the code from a sub to a function, if it will work that way.

Cheers

[MS MVP - Word]
 
macropod, the question was not (I think) to hide the subs from the macro dialog, nor to hide the subs from the users at all, but to hide the code from the users.
how do I make my VBA code invisible to the end user?
my emphasis.

If I understand correctly, it is not a question of preventing the users from seeing (executing) a macro, but preventing them from seeing the code of the macro.

Gerry
My paintings and sculpture
 
Hi Gerry,

Yes, I know that is how the question was framed, but the distinction is lost on many users, so I thought it might be worthwhile mentioning how to hide subs as distinct from modules/forms.

Cheers

[MS MVP - Word]
 
You can hide your code for the enduser in VBA for Access by converting your .mdb to an .MDE file. But of course this is MS Access.
 
macropod - huh? With no desire to hijack the thread, but could you elaborate on "the distinction is lost on many users"?

We are talking about someone trying to look at code. Not look at a list of available macros in the macro dialog, but opening up the VBE to look at code.

I am having trouble seeing the distiction being lost on anyone.

Oh....wait a minute. Right. Sorry. I use the macro dialog so rarely, I forgot there is an Edit button, which of course does open the VBE.

OK. Point accepted. If it is not listed, then there would be no Edit for it. Although, Edit for any other macro would open the VBE. In which case...Private or not, there is the code. So I am not completely convinced of the usefulness. It would take very little to be able to see the code. Simply click Edit for ANY macro.

With a loaded template (that holds the code) the project is unviewable. If the users does not have open rights permissions, then they can not open the file and see the code. A global template/addin, password protected at the VBE level, write-protected at the OS level, sitting in a folder with no user Modify permissions at the Permissions level - that is about the best you can do.

Is that crackable? Of course it is. However, your user is going to have to be pretty darn good. They would have to crack Admin level access to the folder/file permissions, then crack the password in the VBE.

Frankly, I have a hard time seeing anyone who can do that being much interested in dinky VBA code in a document. They would have far more interesting things to play with.

Gerry
My paintings and sculpture
 
Thank you all for the Great response, I must admit I started messing around with VBA about a year ago off and on but lately, since fining this Site I’m motivated more then ever to pursue programming to a high level. Keep it up guys your doing a great job!!!!!!!!!!!!! I will definitely contribute monetary funds to this organization, I’m very pleased with the response times and knowledge base.

As for my original post, I simply wanted to make my code invisible to the end user not my modules or anything else.
 
.....by the way my application is Excel, forgot to mention that earlier.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top