+ Reply to Thread
Results 1 to 5 of 5

VBA to protect/unprotect VBA code?

  1. #1
    Registered User
    Join Date
    06-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    51

    VBA to protect/unprotect VBA code?

    Hi,
    Is it possible to have some code that will unlock the VBA password for viewing VBA modules? The reason I ask, is because I am writing some code to import/export modules (for updating purposes), but I would like to password protect the code. However, you cannot import/export modules if viewing is password protected as far as I know.
    I tried to Google this, but to no avail. I would appreciate if anyone could shed some light on this matter.
    Thanks.

  2. #2
    Valued Forum Contributor
    Join Date
    09-01-2013
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    324

    Re: VBA to protect/unprotect VBA code?

    May be possible with a send key method but not reliable. It's the only way i'm aware of. Feel free to look at this:

    Click Here


    Shelton A.
    If Helpful, Add Reputaion!

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: VBA to protect/unprotect VBA code?

    According to this site:Programming The VBA Editor; "There is no programmatic way to unlock a VBA project (other than using SendKeys). If the project is locked, you must manually unlock. Otherwise, the procedures will not work."

    Perhaps it would be better to save the modules as an Add-In which can be password protected and you can add\remove the entire Add-In programmatically without unprotecting the modules.

    If you do a web search for something like Creating an Excel Add-in, you'll find several guides.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    06-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: VBA to protect/unprotect VBA code?

    Thanks for the suggestions and information. I appreciate it! I will try to work on an Add-In as suggested. Have a great day.

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: VBA to protect/unprotect VBA code?

    It is possible without SendKeys using API calls: http://www.vbaexpress.com/forum/show...ewing-SendKeys
    Remember what the dormouse said
    Feed your head

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Protect/Unprotect a Workbook with code
    By RevJeff in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-17-2012, 10:22 AM
  2. VBA Code to Unprotect a Worksheet then Protect
    By aalbertson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-12-2011, 04:03 AM
  3. Protect/Unprotect code causing out of range error in code
    By Petrolcb41 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-02-2010, 02:34 PM
  4. Protect/UnProtect Project (code) via VBA?
    By brucemc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-05-2006, 12:25 AM
  5. Generic protect/unprotect code through buttons and code?
    By StargateFanFromWork in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-02-2006, 03:35 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1