Unlocking VBA Project

dawsona

Board Regular
Joined
Jul 28, 2002
Messages
66
I have issued a workbook to my colleagues around the world that has password protection on the project as I do not trust them one little bit!!!

What is the VBA code to unprotect it then reprotect it again?

(I need to remove the existing module and replace it with a new version due to changes in the workbook structure).
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
On 2002-09-09 08:07, dawsona wrote:
I have issued a workbook to my colleagues around the world that has password protection on the project as I do not trust them one little bit!!!

What is the VBA code to unprotect it then reprotect it again?

(I need to remove the existing module and replace it with a new version due to changes in the workbook structure).

hi Dawsona
Try doing a seach for this, I'm sure I covered this earlier....
 
Upvote 0
In the sheet module put:

Private Sub Worksheet_Change(ByVal Target As Range)
'
' Macro by Joseph S. Was
'
Application.EnableEvents = False

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="admin"
Application.EnableEvents = True
End Sub

Then in a module add the unlock code and attach your code, if any, before the End Sub.

Note: You can run the un-lock code from a Form-Button or use a hot-key with Macros-Macro-select macro-Options-select your key.


Sub myUnLock()
'This code will unprotect the sheet.
Application.EnableEvents = False
Application.DisplayAlerts = False
ActiveSheet.Unprotect ("admin")

'Add optional code here!

Application.EnableEvents = True
Application.DisplayAlerts = True

End Sub

Then run your code out of the unlock sub, the first macro will password lock the code behind you automatically. You can make the password anything you want. To help hide your password you can password lock your macros form the VBA editor pull-down menu!

Note: this uses hard coded password protection which will decrease the security of the protection. But then again a password does not really deter someone from getting in if they want to, like a door lock does not stop some one from getting in a window, but does stop the causal passer-by from coming in. JSW
 
Upvote 0
Joe, if im not mistaken I think the original post was for unlocking the vb project not the sheet , I think Ivan covered this with send keys,

Brett
 
Upvote 0

Forum statistics

Threads
1,218,497
Messages
6,142,824
Members
450,449
Latest member
Dave Carr QM

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
Back
Top