Excel VBA password

  • Thread starter Thread starter JohnUK
  • Start date Start date
J

JohnUK

Has anyone out there got a solution to protecting a
Workbook/sheet with a password in VB and unprotecting
again?
 
Sub test()
Dim Pwd As String
Pwd = "Secret word"

Sheets(1).Protect (Pwd)
On Error Resume Next
Sheets(1).Cells(1, 1).Value = 3
MsgBox Error
On Error GoTo 0
Sheets(1).Unprotect (Pwd)

ThisWorkbook.Protect (Pwd)
On Error Resume Next
Sheets(1).Delete
MsgBox Error
On Error GoTo 0
ThisWorkbook.Unprotect (Pwd)

End Sub
 

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