Consulting

Results 1 to 3 of 3

Thread: Test if vba password is set.

  1. #1

    Test if vba password is set.

    Note: I am note trying to use this information for hacking. The company I work for is making us protect all our macros. We have thousands and I don't want to have to go into each one to see if it is protected.

    Using vba in excel, I want to be able to test if the vba password is set. Using the below function I can tell most of the time. The only problem is if the "Lock project for viewing" isn't checked and a password is set, the below function will say it isn't protected but when you try to go into the properties it prompts you for a password. Is there a way to tell if it is protected even if they didn't check "Lock project for viewing"?

    Function ProtectedVBProject(ByVal wb As Workbook) As Boolean 
         ' returns TRUE if the VB project in the active document is protected
        Dim VBC As Integer 
        VBC = -1 
        On  Error Resume Next 
        VBC = wb.VBProject.VBComponents.Count 
        On Error Goto 0 
        If VBC = -1 Then 
            ProtectedVBProject = True 
        Else 
            ProtectedVBProject = False 
        End If 
    End Function

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    Hi sin4mike, Welcome to the forum. Please do not cross post without showing the link.

    For Example: http://www.mrexcel.com/forum/showthread.php?t=320104

    People who operate here do so on a voluntary basis, please don't waste their time by asking them to work on a solution when you have already been given something at another forum.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Hmmmm...also cross posted here and i do believe the line of questioning is against our policy look here thread locked!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

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