Lock VBA Project With Code

  • I understand that we can protect the VBA coding through check the "Lock project from viewing in the Tools>VBAProject Properties. However I would like to know if this is possible in code?

    I have a mainworkbook for users that has the VBA coding protected (it contains passwords to unlock protected sheets / main workbook). In my program, the users will be entering data and then push a button which calls a macro to email a "skinny down version" of the main book to other users. Problem is, these users that receive the email will be able to get into the VBA code and see what the password is on the sheets. (even if the new workbook/worksheets are password protected)

    Is there any way when I save the new book to add this protection to the VBA code?

    Thanks in advance

  • Re: Locking Vba Project With Code

    I am all but certain you cannot lock or unlock a project with code.

    How is it that the emailed version has an unlocked project?

    [SIZE=1]Entia non sunt multiplicanda sine necessitate.[/SIZE]

  • Re: Locking Vba Project With Code

    I unlock the main workbook in order to select certain sheets and copy them into a new workbook that I save and email. This new workbook is protected and needs to have the ability via code to be unprotected. The issue is that a user could view the worksheet code and see my password="blah" statement.
    I've seen others attempt to solve this by making a sheet veryhidden and hiding a password on this sheet which is referenced in code. However, a user could just as easily run code which retrieves that cell's value.
    I have also found code to copy lines of code from one module to another workbook module, however, if the project isn't locked, the user can still find this code.
    Any ideas?

  • Re: Locking Vba Project With Code

    I'm still not getting it. If your code is protected, why do you think the user will be able to view your code? The password that unprotects the workbook is different from the password that unprotects the VBA project.

  • Re: Locking Vba Project With Code

    The code is protected in the main book. The issue is trying to protect the code in the new book.
    E.G. VBA Project Protected Workbook 1 contains sheets 1,2,3
    Email creates workbook 2 containing only sheet 3 (carrying over worksheet code containing password text spelled out in the code, along with other code to continue the process)

    How do I hide the code in workbook 2 to keep the user's from seeing the password?

  • Re: Locking Vba Project With Code

    OK. I think I got it now. You're saying that you have code in the actual sheets, not in a module, and I assume you are copying certain sheets into a new workbook and then saving that. If that's the case, I don't know how to protect the code on the new workbook, but I can tell you how to work around it if no one else has a better solution. Instead of copying sheets into a new workbook, copy the entire workbook (this will keep the VBA Project protected) and then delete the sheets that you don't want.

  • Re: Locking Vba Project With Code

    Like Shg, I'm pretty sure you cannot lock or unlock VBA code via VBA code. If it were possible, it would be a security risk.

    I'm locking this thread before some hacker jumps with some code that can be used for bad intent, sorry.

    I suggest you start a new thread without assuming your means to an end.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!