Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2004
    Posts
    15

    Question Unanswered: protect vba code

    Is there a way to protect vba code from viewing ?

  2. #2
    Join Date
    Oct 2003
    Posts
    1,091
    No absolute way - let's face it, if you have a computer, someone could break the security, and especially with MS Office products. However, the most common way of protecting the code (from 99% of the people who use Excel/Word) is this:

    1. In VBE goto Tools | VBE Project Properties...

    2. Select the Protection tab

    3. Check the box for "Lock project for viewing"

    4. Input and confirm your password

    5. Save and close the workbook
    old, slow, and confused
    but at least I'm inconsistent!

    Rich
    (retired Excel 2003 user, 3/28/2008)

    How to ask a question on forums

  3. #3
    Join Date
    Oct 2003
    Posts
    1,091
    Oh yeah, and remember your password!
    old, slow, and confused
    but at least I'm inconsistent!

    Rich
    (retired Excel 2003 user, 3/28/2008)

    How to ask a question on forums

  4. #4
    Join Date
    Sep 2003
    Location
    MN US
    Posts
    313
    Quote Originally Posted by shades
    No absolute way - let's face it, if you have a computer, someone could break the security, and especially with MS Office products. However, the most common way of protecting the code (from 99% of the people who use Excel/Word) is this:
    For what it's worth, last week my boss locked himself out using this method (and forgetting his PW.) Took about 5 minutes on Google to find a utility to reset the password.
    So 99% might be more like 97%

  5. #5
    Join Date
    Oct 2003
    Posts
    1,091
    quot et demonstratum
    old, slow, and confused
    but at least I'm inconsistent!

    Rich
    (retired Excel 2003 user, 3/28/2008)

    How to ask a question on forums

  6. #6
    Join Date
    Aug 2004
    Posts
    15
    Thanks, it works

  7. #7
    Join Date
    Feb 2004
    Posts
    533
    FWIW - I like to separate my code from the data. This way I can hide the code file from view and have it open as read-only (since it is fixed code it will not be updated during use) With the file hidden it will not show in the workbooks list. I keep master copies of programs so if something gets altered I can replace it quickly.

    Password protection and saving as a .xla gives more protection, but for internal stuff hiding and using read-only works good without having to keep up with passwords.

    Here's utility code I use to to hide, save, and close a code file after I've finished editing and testing.

    Code:
    Sub CloseNhide()
        Dim visbook As Object
    
        Set visbook = ActiveWorkbook
        ActiveWindow.Visible = False
        visbook.Save
        visbook.Close
    End Sub

    /
    ~

    Bill

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •