Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Self distruction when someone trying to open VBA module

  Asked By: Boell    Date: Dec 29    Category: MS Office    Views: 712
  

I have an excel file with 6 vba modules. Do you have any ideas what
possible macro to delete existing module in this file.

What i need is, when someone trying to open with wrong password in a
protect module in my excel file, then it will delete a module.
Try 2 atempt thent delete another module.

It would be appreciate for your kind support and sugestion in this
case.

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Akins Massri     Answered On: Dec 29

Courtesy of the website ozgrid.com I found code which could delete  a module

Dim vbCom As Object
Set vbCom = Application.VBE.ActiveVBProject.VBComponents

vbcom.delete vbcom.item("Module2")

But I have no idea how you are going to be able to use it within a module  as
VBProject does not expose its passwords properties to the outside for obvious
reasons.

 
Answer #2    Answered By: Sally Pierce     Answered On: Dec 29

I have code that will delete  the modules
(I remove the modules  and protect the worksheet when I send the final
report for distribution),
but how do you plan to determine the failed password  attempts?

Plus, what good is it to delete a single module?
Once one or more modules are removed, won't execution results become
unpredictable? If the person fat-fingers the password the first time,
but corrects his mistake the second, he'll be missing a module  and
probably needs to start over anyway...

Well.. if you can figure out the failed password, here is what I use:

Dim VBComp As VBIDE.VBComponent
Dim VBComps As VBIDE.VBComponents
For Each VBComp In VBComps
'MsgBox VBComp.name
Select Case VBComp.Type
Case vbext_ct_StdModule, vbext_ct_MSForm, _
vbext_ct_ClassModule
VBComps.Remove VBComp
Case Else
With VBComp.CodeModule
.DeleteLines 1, .CountOfLines
End With
End Select
Next VBComp

 
Answer #3    Answered By: Erma Henry     Answered On: Dec 29

No matter if you password  protect a VBA module  or a workbook or a
worksheet, unfortunately there is no way to check if a wrong  password
is entered.

 
Didn't find what you were looking for? Find more on Self distruction when someone trying to open VBA module Or get search suggestion and latest updates.




Tagged: