how do i know if vba project is protected?

muffins

Board Regular
Joined
Jun 18, 2002
Messages
86
Hi everyone,

May I know is there a way to check if a workbook's VBA code is already protected by a password?

Thanks!!
 

Some videos you may like

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

elgringo56

Well-known Member
Joined
Apr 15, 2002
Messages
869
Open the workbook
Open the VBA editor (ALT F11)
go to "Tools"
go to "VBA Project Properties"
go to "Protection"
If the VBA is protected, there will be asterics in the Password blanks. I hope this answers your question
 

michaeldh

Board Regular
Joined
Jun 11, 2002
Messages
201
Hi,

Open up the visual basic editor which stores the Macros. If you can double click a module and edit the macro then it is not protected. If the macro is protected it will prompt you for a password when you double click it

When a user protects a vba module, there is an option to hide all of the macro contents (a little check box to tick). In this situation all you can see is something like this in the visual basic editor:

+VBAProject("Filename")

The best way for you to get your answers is to protect and unprotect a vba project yourself. Give it a shot and see how you go.

Michael.
 

elgringo56

Well-known Member
Joined
Apr 15, 2002
Messages
869

ADVERTISEMENT

I dont know if you can programatically. Is that really a word????
 

Ivan F Moala

MrExcel MVP
Joined
Feb 10, 2002
Messages
4,209
On 2002-08-16 21:54, muffins wrote:
how do i check programatically? thankeee!!

Hi muffins have a look @ this code which will
list the projects and modules. It checks 1st
to see if the project is protected!
Amend as required.

<PRE><FONT color=#008000>'// Needs reference to the Microsoft Extensibilty Library
</FONT>
<FONT color=blue>Sub </FONT>Prj_Protected()



<FONT color=blue>Dim </FONT>oVBP <FONT color=blue>As</FONT> VBIDE.VBProject

<FONT color=blue>Dim </FONT>oVBC <FONT color=blue>As</FONT> VBIDE.VBComponent

<FONT color=blue>Dim </FONT>x



x = 1

<FONT color=#008000>'// Use err check in case a workbook is NOT saved!
</FONT>
<FONT color=blue>On Error</FONT> <FONT color=blue>Resume </FONT><FONT color=blue>Next</FONT>

<FONT color=#008000>'// Loop through each Project
</FONT>
<FONT color=blue>For </FONT>Each oVBP In Application.VBE.VBProjects

<FONT color=#008000> '// Is it prtected?
</FONT>
<FONT color=#008000> '// VBE Constants
</FONT>
<FONT color=#008000> '// vbext_pp_locked = The specified project is locked.
</FONT>
<FONT color=#008000> '// vbext_pp_none = The specified project isn't protected.
</FONT>
<FONT color=blue>If </FONT>oVBP.Protection = vbext_pp_none Then

<FONT color=#008000> '// NO, so list the Modules
</FONT>
<FONT color=blue>For </FONT>Each oVBC In oVBP.VBComponents

Cells(x, 1) = oVBP.Filename & ":" & oVBP.Name & "." & oVBC.Name

x = x + 1

<FONT color=blue>Next</FONT>

<FONT color=blue>End If</FONT>

<FONT color=blue>Next</FONT>



<FONT color=blue>End Sub</FONT>




</PRE>
 

elgringo56

Well-known Member
Joined
Apr 15, 2002
Messages
869

ADVERTISEMENT

LOL, where do you find this stuff, Ivan. Un believable. You know your stuff, thats for sure
 

muffins

Board Regular
Joined
Jun 18, 2002
Messages
86
wow thanks... but i hv another qn *blushed*..

suppose a workbook's project has been protected by a password, how do i check if the project has been opened?
 

Ivan F Moala

MrExcel MVP
Joined
Feb 10, 2002
Messages
4,209
On 2002-08-17 00:06, muffins wrote:
wow thanks... but i hv another qn *blushed*..

suppose a workbook's project has been protected by a password, how do i check if the project has been opened?

Hi muffins...sorry I'm not with you ??
Do you want to check if a password protected project has been opened ?? eg say if you have protected the project then you want to check if it has been opened ? Is that correct ? If so then I'm not sure there is a simple way to check this...I can think of a long winded way...but coding gets messy...
If I was to do this then I would basically look at an Event driven macro to detect if the Projects Windows was open, if so then generate code to generate either a hidden file note with date & time + User ad/or email it off...BUT...
 

HockeyPuck1

New Member
Joined
Apr 2, 2018
Messages
1
how do i check programatically? thankeee!!

The reply from 2002 doesn't list the extensibility reference. Also the code didn't seem to run on Excel 2013. Try this:

Sub Prj_Protected()
' set a reference to MS Visual Basic for Applications Extensibility 5.3
On Error Resume Next
ThisWorkbook.VBProject.References.AddFromGuid _
"{0002E157-0000-0000-C000-000000000046}", 5, 3

Dim vbPrj As VBProject
Dim vbCom As VBComponent
Set vbPrj = Application.VBE.VBProject
Set vbCom = Application.VBE.VBProject.VBComponents
Dim x As Integer
x = 1
On Error Resume Next
For Each vbPrj In Application.VBE.VBProjects
If vbPrj.Protection = vbext_pp_none Then
For Each vbCom In vbPrj.VBComponents
Cells(x, 1) = vbPrj.Filename & ":" & vbPrj.Name & "." & vbCom.Name
x = x + 1
Next
End If
Next
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,912
Messages
5,598,828
Members
414,260
Latest member
joishe

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top