Results 1 to 3 of 3

Thread: Programmatically unlock VBA Project

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    15
    Rep Power
    0

    Programmatically unlock VBA Project

    In order to run some of the Subs on my new Form Administration Page (specifically, the two sections of code that list all functions in ThisWorkbook and Module1), I need to be able to programmatically unlock the VBA Project (which is protected to prevent users from screwing with the code, and I have been told that this is not optional).

    The unlock will only happen when the Form Administration worksheet is initialised, and access to this will be (in the final version) controlled by checking the current user's ADlogin against a list of 'authorised administrators' (which will hopefully minimise unauthorised/accidental access).

    I have done a lot of searching on this and most initial responses seem to be "you can't". However, I have also come across two (admittedly quite old) ways that this can, in fact, be done - SENDKEYS and the Windows API.

    Having looked into these, I am not willing to risk the uncertainty and unreliability involved in using the SENDKEYS method, so have inserted the API code into Module1 of my workbook (attached). However, while it does unlock the project, it is not behaving entirely as it claims/as desired.

    For example: It currently prompts for a password (it is supposed to enter it automatically), and none of the 'debug' MsgBox calls are being initialised. It is also opening the VBA Project Properties window before finally showing an error that the Password window couldn't be found (even though it was manually input earlier).

    The code is currently called from a Worksheet_Activate() event, so if you switch to Sheet2, then back to Form Administration, you will see what I mean. Password is "test", in case it is needed.

    Does anyone have any ideas where this is falling over/misbehaving?
    Attached Files Attached Files

Similar Threads

  1. How To Protect VBA Project From Unauthorized Access
    By lucio5295 in forum Excel Help
    Replies: 2
    Last Post: 12-01-2013, 02:09 PM
  2. Replies: 5
    Last Post: 04-18-2013, 02:30 AM
  3. Programmatically format VBA buttons
    By Belleye in forum Excel Help
    Replies: 9
    Last Post: 09-25-2012, 11:18 AM
  4. Scroll Lock and Unlock using VBA
    By LalitPandey87 in forum Excel Help
    Replies: 2
    Last Post: 11-08-2011, 08:59 AM
  5. Add ribbon programmatically to Excel 2010 using VBA
    By heapifyman in forum Excel Ribbon and Add-Ins
    Replies: 6
    Last Post: 07-18-2011, 09:16 PM

Posting Permissions

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