Change Workbook Password

  • Thread starter Thread starter iperlovsky
  • Start date Start date
I

iperlovsky

Does anyone know how to change the password using VBA for the entire workbook
from "x" to nothing - so that the user is not prompted to enter a password
next time the workbook is opened?

Thanks...
 
You'll need the password, but here's some code I've had that you can adapt.

'/============================================/
Private Sub ProtectPswd()
'template for unprotecting/protecting worksheet
Dim blnProtectContents As Boolean
Dim blnProtectDrawingObjects As Boolean
Dim blnProtectScenarios As Boolean
Dim strPassword As String

'set default for whether worksheet is protected or not
blnProtectContents = False
blnProtectDrawingObjects = False
blnProtectScenarios = False

'check if worksheet unprotected
' if it's protected, get various information
On Error Resume Next
If Application.ActiveSheet.ProtectContents = True Then
blnProtectContents = True
If Application.ActiveSheet.ProtectDrawingObjects = True Then
blnProtectDrawingObjects = True
End If
If Application.ActiveSheet.ProtectScenarios = True Then
blnProtectScenarios = True
End If
'protected so try password
strPassword = InputBox("Enter Password: " & vbCr & vbCr & _
"If there is no password, press ENTER." & vbCr & vbCr & _
"ONLY enter Password if source of this macro is TRUSTED!!!", _
"Password to Unprotect Worksheet...", "")
ActiveSheet.Unprotect password:=strPassword
'password didn't work - still not unprotected so stop process
If Application.ActiveSheet.ProtectContents = True Then
Exit Sub
End If
End If
On Error GoTo 0

' ++++++++++++++++++++++ put coding here +++++++++++++++++

'set worksheet back to original protected/unprotected state
On Error Resume Next
ActiveSheet.Protect password:=strPassword, _
DrawingObjects:=blnProtectDrawingObjects, _
Contents:=blnProtectContents, Scenarios:=blnProtectScenarios

End Sub
'/============================================/

--
Hope this helps.
If this post was helpfull, please remember to click on the ''''YES''''
button at the bottom of the screen.
Thanks,
Gary Brown
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top