lezawang
Well-known Member
- Joined
- Mar 27, 2016
- Messages
- 1,805
- Office Version
- 2016
- Platform
- Windows
Hi
The code below will unprotect workbook if the user typed the right password. But when I typed wrong password, excel sent me to VBA with run time error message asking to enter the right password. How can I improve that so Excel would give an error message but stay in excel. Thank you
The code below will unprotect workbook if the user typed the right password. But when I typed wrong password, excel sent me to VBA with run time error message asking to enter the right password. How can I improve that so Excel would give an error message but stay in excel. Thank you
Code:
Sub wb_unprotect()
'unprotect workbook
Dim x As String
x = InputBox("enter password")
Workbooks(1).Unprotect Password:=x
End Sub