Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to detect unprotected VBA project

Status
Not open for further replies.

cbdsolutions

Programmer
Oct 28, 2003
3
US
What are the codes to detect that a VBA project associated with an Excel Workbook is unprotected and what are the codes to delete subs within each modules and object sheets?
 
Before we try and give an answer, please explain why.

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
The following function should return True if a workbook's VBA code is protected :
Code:
    Function ProtectedCode(WB As Workbook) As Boolean
        ProtectedCode = WB.VBProject.Protection
    End Function
You can use

[tab]ActiveWorkbook.VBProject.Protection

for the active workbook.

You can routines code for deleteing VB code from workbooks at Chip Pearson's website :

[tab]
A.C.
 
< Well I was with xlbo before acron jumped the gun as in why? >

I cannot see what the problem is. What gun ?

A.C.
 
<< Well I was with xlbo before acron jumped the gun as in why? >

I cannot see what the problem is. What gun ?

A.C.>

Just thinking on the lines or why would anyone want to detect if the VBAProject was unprotected or not. Is the OP the workbook owner or not?

Chris ;-)

Visit for great xl and xl/VBA help
 
It is very easy to establish if any particular workbook is protected or not interactively by simply trying to acces the code. So why not make the same process simple via code ?

I do not think cbdsolutions needs to explain to me why he is trying to do something. I have no reason to think he is up to anything sinister, and even if he is, establishing the protection state of a VB Project using code is not giving him access to that code. He would need the Password to tamper with the code.

It would seem to me that perhaps the poster is dealing with a number of workbooks to remove code, but if a workbook is protected it would not possible. Hence a need to test.

Hope this satisfies.

A.C.
 
A.C. - fair enough from your point of view and I respect your opinion - as I read the OP's question <What are the codes to detect that a VBA project associated with an Excel Workbook is unprotected and what are the codes to delete subs within each modules and object sheets> I assumed they wanted to delete modules from protected VBA projects - maybe I misunderstood as to why(?)

Chris ;-)

Visit for great xl and xl/VBA help
 
To delete code from a protected VBA project you would need the Password (or a Password cracker).

None of the information or the link I provided would enable tampering with protected code.

I can assure you that I would in no way aid and abet any attempt to 'crack' any code.

Regards,

A.C.
 
Fair enough Acron - just wanted to be sure myself as this kinda info can be used maliciously....say for example, go through all workbooks in a directory and if the project is unprotected, delete everything in it.....

From my point of view, I know if my projects are protected or not so I'm sure you can understand my question...

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top