protecting a macro

Y

ynissel

Is there a way to do this inside a macro?
VB Editor Tools, VB Properties, Protection, Lock
project for Viewing with a password.


Meaning I want to protect my macro from viewing but I dont want to have to
unprotect it everytime I use the file?

Thanks,
Yosef
 
J

JE McGimpsey

ynissel said:
Is there a way to do this inside a macro?
VB Editor Tools, VB Properties, Protection, Lock
project for Viewing with a password.


Meaning I want to protect my macro from viewing but I dont want to have to
unprotect it everytime I use the file?

Well, in WinXL you can use the SendKeys method to lock and unlock the
project, but there's no way to programmatically do it in MacXL (I don't
know if there's a way to use the GUI mode of applescript or not).

Not sure what your particular application is, but is there a good reason
you're unlocking the project every time you use the file? Normally I
keep files unprotected during development, only locking them when I'm
ready for production, meaning that I shouldn't have to change the code
again (at least until the next revision).

This is much easier when one keeps one's workbooks containing code
separate from workbooks with data. My applications typically load the
code workbooks as add-ins, then open data workbooks as the user requires.

Note that VBA project protection in XL is not particularly difficult to
bypass so one shouldn't depend on it to keep your code secure.
 
E

Edwin Tam

There is no way on the Mac you can protect/unprotect a VBA Project via a
macro.

But this doesn't mean there is a standard way to do it in Windows. In
Windows, a trick to do it is with SendKey: simulating keyboard inputs.
However, this is very unreliable and is not recommended.

If you want to unprotect your project every time you use it, you can set a
password manually, and then double-click the project in VBA Editor to unlock
it every time.

I work in an investment bank and I have VBA Projects which I need to unlock
every time I use them.

It's true that VBA password protection is weak, as the password is merely
saved in several bytes within an Excel file. Some people who know the secret
can simply hack into the file, and delete those bytes, and the password will
be removed completely. But such "secret" has been well maintained by people
in the industry for years, therefore, the password protection should still
be able to protect access from 99.9999999% of the population. No need to
worry too much. (Nothing is truly secure anyway...)

Regards,
Edwin Tam
http://www.vonixx.com/
 
J

JE McGimpsey

Edwin Tam said:
But such "secret" has been well maintained by people
in the industry for years, therefore, the password protection should still
be able to protect access from 99.9999999% of the population. No need to
worry too much.

I'd put it at a significantly lower percentage, given that it's been
published more than once on the Excel newsgroups, and is archived and
easily accessible via Google groups. In any case, it's at least several
orders of magnitude more than 6 people in the world...

Still, I agree that one is safe from the casually inquisitive user.
 

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