I need to know how to protect a VB project (so that no users can view or edit it) in VBA. The reason is I have a loop that I need to run it in for multiple workbooks.
I need to know how to protect a VB project (so that no users can view or edit it) in VBA. The reason is I have a loop that I need to run it in for multiple workbooks.
Actually, I need to know how to do this in VBA. I cannot go through hundreds of workbooks and set it manually. Using the same password is fine.
Eric,
Just a warning, if your VBA code tries to change itself or a module etc then it will throw up errors and not work correctly when locked. I found that out the hard way.
Mowgli
I will be locking them when I finish creating and modifying them. I will not modify on the fly! When I modify a workbook, I delete it and re-create it. Locking the VB project will be the last step, but I need to do it in code.
EDIT: I just tested it and when the VB project is protected it does not affect the functionality of the macro I have written. It still works fine.
Last edited by Eric09; 09-24-2012 at 07:51 AM.
Eric,
So far as I am aware there is no method of automatically locking the VBA project using code. I have seen "sendkeys" suggested as an option however the general concensous seems to be avoid these like the plague. Sorry that I can't be of more help but maybe someone else in the Forum will know differently?!?
The error I was talking about earlier was when the code runs it may sometimes change depending on items in the sheet or user input. This is what caught me out, after testing my code and having it run perfectly I locked the VBA project, ran the Macro and... Error
I don't know. Maybe there is a workaround. I just need to hide the macros behind the sheet so that the users I email the workbooks to will not be able to view or edit them. There are no modules and I have no problem with them creating their own modules or macros, I just don't want them playing with mine. My macros (in the sheets) are there to prevent getting crappy, ambiguous data back. And I need it to stay that way...if at all possible.
Eric,
Do the workbooks that are affected by the loop are new or existing workbooks?
I create the workbooks and the macros in them using VBA (a split). They are all in the same folder, hundreds of them. So, I am not able to open them all manually and modify them.
Are those workbooks in the same format or all the same?
Is it possible for you to use a template with a macros on it (VB Project password protected)?
Then everytime you run the macros "using VBA (a split)", you just open that template then do the things.
I could but I need the macros in the workbooks to work. There are dependent drop downs and Cols. D E and F and the macros are designed to reset the values in E if the user changes the choice in D. As far as I know, there is no worksheet function that will automatically delete values based on a cell change. Therefore the macros have to be in the workbook the users get.
Last edited by Cutter; 09-24-2012 at 07:32 PM. Reason: Removed whole post quote
sendkeys method http://www.mrexcel.com/forum/excel-q...via-macro.html
(may or may not be reliable)
api method http://www.standards.com/Office/SetV...tPassword.html
should be more reliable
Josie
if at first you don't succeed try doing it the way your wife told you to
Good link Joseph, I hadn't seen that method before
Thanks Joseph.
May I ask a stupid question, re: the method in the second link? Why is the code to perform such a simple task as to password protect a little bit of VBA code a mile long?
because there is nothing in the excel object model that allows you to do it-presumably following the foolish notion that that would make project security easy to break (which it is anyway of course). therefore you have to trigger dialogs then get handles to controls and manipulate them programmatically-basically a literal automation of the manual steps. in my opinion it's usually a waste of time-if someone is likely to tamper with your code it's easy to break protection or just disable macros
Because it isn't built into Excel, there's no way to do it. It therefore needs doing the hard way, by going through all the steps and identifying the relevant parts by code
But, assuming I do get the VBA project protected, is it easy enough for someone who knows nothing at all about VBA or advanced Excel to disable the macros? If the VBA is not protected, all they need to know is how show the developer ribbon (a 5 minute Google search) and the location of the 'delete' key.
if they can google they can break it ;-)
why would they though? if you get a workbook back without your code in it just refuse it
Ok. At this point, it looks like I will have to do that. Hopefully, they won't have time to bother.![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks