PDA

View Full Version : Test if vba password is set.



sin4mike
05-16-2008, 07:11 PM
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

Aussiebear
05-16-2008, 10:20 PM
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.

Simon Lloyd
05-18-2008, 01:26 AM
Hmmmm...also cross posted here (http://www.ozgrid.com/forum/showthread.php?t=91485) and i do believe the line of questioning is against our policy look here (http://www.vbaexpress.com/forum/faq.php?faq=psting_faq_item#faq_hack_faq_item) thread locked!