PDA

View Full Version : SECURING VBA CODE



t64
09-09-2007, 01:03 AM
Hi all.

I've recently downloaded an Excel sheet, and when trying to look at the VBA code, I was prompted for a password. This is great for securing your code. How can I have such a function? Any code?

Sky86
09-09-2007, 01:36 AM
Hi,

I dono is Coding needed or not. but i do like this.

1. In Microsoft VB, Goto Tools --> VBA Project Propreties --> Protection
2. Set the Password there.
3. Save and exit.
4. The Next time You open it, VB will ask for the Password

Hope this will Help.

mdmackillop
09-09-2007, 01:57 AM
But be aware that this is not a high level of security.

t64
09-09-2007, 03:35 AM
sky 86..
No.. this is not about Protecting your project properties. In the file I saw, as soon as I try to go to the Visual Basic Editor (Alt F11), I am prompted for a password. That means, I can't even enter the code section without a password! That's what I'm after. Any ideas?

mdmackillop.. what are you on about? what is MVP? Never heard of it. Is that how it's done??

mdmackillop
09-09-2007, 03:53 AM
Have a look at this discussion
http://www.mrexcel.com/archive2/63700/73763.htm

Regarding MVP (http://mvp.support.microsoft.com/mvpfaqs)

rory
09-10-2007, 02:50 AM
If this is a commercial thing you are developing, be aware that most users wouldn't take kindly to you trying to disable their access to the VBEditor. You'd certainly lose me as a customer instantly!

unmarkedhelicopter
09-10-2007, 07:17 AM
If this is a commercial thing you are developing, be aware that most users wouldn't take kindly to you trying to disable their access to the VBEditor. You'd certainly lose me as a customer instantly!

And me.
In fact like 'some code' posted by 'some people' here, I might take to dissecting your spreadsheets, removing ALL passwords, protection and 'inconveniences' and maybe reposting it in it's sanitised form. But MOST LIKELY I just wouldn't go near it with a barge pole.
You'd be surprised (most likely you wouldn't (but I am)) by the number of people who think it's clever to mess with peoples settings, cos it's the way "they" work, "so why not everyone else ?"

rory
09-10-2007, 07:32 AM
I've ceased being surprised by most things people do, but I have reached the point where I often won't tell people how to do some things if I think it's a really bad idea (like changing the user's screen resolution and regional settings just to save coding time!!)

On the original question, if you want proper security use a language that compiles into a dll (or xll or exe). VBA project passwords can be broken instantly by commercial software and in a couple of minutes by anyone with a hex editor, though obviously they will deter the casual user.

unmarkedhelicopter
09-10-2007, 07:49 AM
Rory - You are SO right ! (and probably SO much more mature, and I don't mean to infer you are older ;) ) Like Bob once said, "just walk away" if they are stupid, there's nothing you can do to fix them. (unless the fix is "premature life period expiration" and generally there is a law against that !))

rory
09-10-2007, 07:59 AM
Try telling my wife I'm mature and see how long she takes to stop laughing! :devil2:
Most of the time I couldn't walk away as it was my job to do that stuff. I did, however, develop a system of ignoring every request the first three times it was asked for; the important stuff was always requested again, but a lot mysteriously evaporated while I got on with the stuff that really had to be done. Of course, now I just do it for fun, so if it ever stops being fun, I can just wander off! :)
Oh, and I always hold down the shift key while opening workbooks until I've read the code...

unmarkedhelicopter
09-10-2007, 08:11 AM
Rory - Yeah ! most FDS's I see have contradictory requirements or stuff that just plain seems crazy, even when written by the "Current system's Goto Guy/Guru/Expert etc."
Mind you I have also come across inocuous stuff that you think would be easy to drop but is actually there for a very good reason (even if the "Guru" has forgotten it)
But the most enfuriating bits I find are the multiple indexes to maintain compatibility to systems and indexes that either no longer exist or have already been converted to use the same indexes.

t64
09-10-2007, 08:55 PM
like hello ? stay on topic !!

it doesnt matter why I'm after the code..
what matters is that the coding technology is out there, and it's most interesting, and I'm looking for someone who might know..

the file I saw was not exe or dll.. it was a normal excel .xls file, in which you could not enter the VBA editor in any way.. a popup would always show asking for a password.. that's good coding..

any ideas?

malik641
09-10-2007, 10:09 PM
the file I saw was not exe or dll.. it was a normal excel .xls file, in which you could not enter the VBA editor in any way.. a popup would always show asking for a password.. that's good coding...

any ideas?
Malcolm gave you a link to a thread that has answered your question:

Have a look at this discussion
http://www.mrexcel.com/archive2/63700/73763.htm
Like hello? Pay Attention!! j/k :)

My opinion, is if you are going to do this, I would highly suggest to figure out a way to only have one single instance of Excel open that uses this "blocking VBE" feature, because you shouldn't halt them from accessing their own code in their own workbook, ya know?

Don't forget that you'll also have to disable menu items as well (as I don't know how you can 'catch' the event that someone clicks on the VBE item in the Tools-->Macros menu.)

mdmackillop
09-11-2007, 12:26 AM
Try entering
disable alt f11
into Yahoo/Google search for more choice

johnske
09-11-2007, 12:54 AM
??? maybe I'm missing something here, but...

1) to access the VBE, I just click on the Visual Basic Editor icon (Tools > Macro > Visual Basic Editor {place a copy on the toolbar so it's available with a single click}) or I might right-click and use "View Code" but I simply never ever use ALT+F11

2) disabling ALT+F11 still allows me to enter the VBE using either of my normal methods (above)

...so what's the point???


t64: there's no code needed, read post 2 above and just try it, keep in mind what is said in post 3. Also keep in mind this


You'd certainly lose me as a customer instantly! IMO there's nothing wrong with using VBE protection to stop accidental changes or erasures, but let the password be known and readily available for those with legitimate reasons for wanting to make changes to the code.

unmarkedhelicopter
09-11-2007, 03:50 AM
Sorry, moved to bottom of thread.

unmarkedhelicopter
09-11-2007, 03:52 AM
like hello ? stay on topic !!

it doesnt matter why I'm after the code..
what matters is that the coding technology is out there, and it's most interesting, and I'm looking for someone who might know..

Hmmmm ! Yes ... I was reticent to help you before but now that you've put it in such charming words and shown such attention to the solution shown you by md and ignored all advice to the contrary shown by everyone else and shown the futility of it by johnske ... I'll get right on it ...

I just need to wait until hell freezes over ... :whistle:

Bob Phillips
09-11-2007, 04:00 AM
I have to say UMH that I agree with the OP. You and Rory went off on a trip that was just for you two, nothing to do with the question. If you want to do that, start your own thread.

rory
09-11-2007, 04:06 AM
It's a fair cop, we did go well off topic (if only for a couple of posts), for which I apologise; but there had been several pertinent answers prior to that which seemed to be ignored completely or misinterpreted (I never suggested that you had to have a dll to block the VBEditor, merely that it would provide far better security).

Bob Phillips
09-11-2007, 04:24 AM
Maybe so (but here I am doing the same, so if the OP pulls me up I accept that) , but the problem is that for someone who is looking for help may find all that much noise going on to be confusing and may miss the pertinnet threads.

Simon Lloyd
09-11-2007, 05:54 AM
It seems to me that the if the Op is unable to view the VBE then it is simply a case of the Project being protected or an Add-in that is selectively protecting the project, if it is the latter then that would be very interesting and useful, moreover it would be even better if the code could be viewed but not modified. I am all for people being able to view the code that helps them with their tasks or routines, it may, in some way, help them understand how to create routines of their own that will expedite their work!, if we can spread a little knowledge as everyone here and other forums have done for me then there would be many more intelligible questions here rather than the mundane.......only slightly off topic!

rory
09-11-2007, 06:18 AM
If you can't even view the VBE then it is more than the project being protected - that would simply prevent you from viewing the code for that project but allow you to alter other code as you see fit. I have no issue with projects being protected other than the fact it's not as secure as some people might think; I would take exception to someone trying to prevent me from accessing the VBEditor at all since that would prevent me from modifying my own code too.

unmarkedhelicopter
09-11-2007, 07:35 AM
The only way, to resolve this once and for all, would be to look at the WrkBk the OP is talking about and pull it apart, post it and someone will do just that.

I would suggest that anyone re-posting the code consider the confidentiality of the original work and remember that we are only looking at the area concerning project protection. And so delete everything but that which is needed.

I'm sure I don't need to remind enyone but ...
Do not discuss cracking techniques in line with this sites policy !!!
Read the FAQ's

t64
09-12-2007, 12:33 AM
xld - u make an excellent point!

hmm thanks everyone..

protecting VB properties isn't exactly protecting your code from being seen, edited, etc..

restricting ALT F11 is a good idea, but there are many other ways to get to the VB editor, plus as mentioned above by someone, Other workbooks will have problems..

I wonder how they've done it on the sheet I saw.

Well if i find anything, I'll try to post it here.

Cheers.

t64
09-12-2007, 12:37 AM
yes sure, i'll upload the file for you guys to see what im on about !

(obviously i cant uplaod the code since i can't access it!)

how can i attach a file ?

mdmackillop
09-12-2007, 12:40 AM
how can i attach a file ?
Use Manage Attachments in the Go Advanced section.

johnske
09-12-2007, 12:55 AM
...protecting VB properties isn't exactly protecting your code from being seen, edited, etc...As I said - try it - because that's exactly what it does do. (You're not protecting VBA project properties, protection is one of the VBA project properties)

t64
09-12-2007, 01:18 AM
As I said - try it - because that's exactly what it does do. (You're not protecting VBA project properties, protection is one of the VBA project properties)

when i select the vb project, the only properties in the properties took box is "name", nothing else. What protection are you exactly talkin about? I thought it was through the top menu options:
Tools -> VBA Project Properties --> Protection tab --> Password put in

but that doesn't stop your code from being seen or anything like that..

are you talking about something else? if so, please describe how to access it in details.

Thank you.

johnske
09-12-2007, 01:30 AM
in the VBE window (ALT+F11 is one way to get there)
click Tools
click VBAProject Properties...
click Protection
click Lock Project for Viewing
enter a password in the password field
enter the password again in the Confirm Password field
click OK
save the workbook and close it...

re-open the workbook, look in the VBE window and you'll find that the code is now hidden

t64
09-12-2007, 03:32 AM
johnske, yes thanks, that's right, that locks ur code..

i was initially interested in locking access to the VB editor all together because i thought the code to do that is interesting..

ill attach a file once i get home showing what i mean..

thanks.