Friend asked me a little query.
he wants VBA to delete his Target Sheet automatically if the Target Sheet is Unprotected!
Now, that's something easy but it's not! Not at all! unless you know the best way to achieve that task using an available property of the Sheet Object.
There's a Sheet property called,."ProtectContents"
Here's how you can perform..
Step 1: Choose TargetSheet
Step 2: Open Code Editor for that Target Sheet Object from VBE.
Step 3: Paste Below Code
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error Resume Next
Application.DisplayAlerts = False
If Sheets("SheetName").ProtectContents = False Then
Sheets("SheetName").Delete
End If
Application.DisplayAlerts = True
On Error GoTo 0
End Sub
That's it!
Now if someone will illegally try to crack your Target Sheet password from your workbook then after any cell selection by the user will trigger the above Sheet Selection Event.
The Code further investigate using the mentioned property whether the sheet is protected or not. if it is unprotected instead of Protected then Code will delete the sheet in a fraction of seconds.
Many of us do have an idea of this and many of us would not. So this strategy will help freelancers to make their templates more commercially protected!
Keep Learning.
Kamal Bharakhda
Subscribe to:
Posts (Atom)
IsValidPasswordString Function
'Following function will verify if the password string contains following characters or not? Rem : List of Characters Group - ASCII Rem ...
-
Here is the complete VBA code to import XML Data into the Excel Workbook in a completely dynamic approach. Look at the following video. ...
-
Hello Mates, When you work with Userform in Excel VBA, usually sometimes you need to retrieve or reflect currency figure in the Userfo...
-
'Following function will verify if the password string contains following characters or not? Rem : List of Characters Group - ASCII Rem ...