ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Password protect an Excel document (https://www.excelbanter.com/excel-programming/277317-re-password-protect-excel-document.html)

Paul B[_7_]

Password protect an Excel document
 
Steve, give this a try,
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
'must lock VBA project so you can't see the password in it
'Input box to verify password before saving
'put in this workbook module
Dim myPassword As String

myPassword = InputBox(prompt:="Please enter the password to proceed:", _
Title:="Password is required to save this file.")
'change password to what you want
If myPassword < "123" Then
MsgBox "Password Is Not Correct"
Cancel = True

Else
End If
End Sub


--
Paul B
Always backup your data before trying something new
Using Excel 97 & 2000
Please post any response to the newsgroups so others can benefit from it
** remove news from my email address to reply by email **

"Steve Quiroz" wrote in message
...
Need to know how allow users to enter a password before
they can save changes to the workbook?





steve

Password protect an Excel document
 
Steve,

Just an added note:

If the workbook is opened without macros enabled, than the user can
do whatever they want.

There are stratagies to hide all worksheets (xlVeryHidden) with only an
instruction page visible saying that sheets cannot be viewed unless macros
are enabled. Have an on open event macro to unhide the sheets and a
close event macro to rehide the sheets.

Protect your code and go from there.

But - a serious person can find a way to "hack" the password...

--
sb
"Paul B" wrote in message
...
Steve, give this a try,
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
'must lock VBA project so you can't see the password in it
'Input box to verify password before saving
'put in this workbook module
Dim myPassword As String

myPassword = InputBox(prompt:="Please enter the password to proceed:", _
Title:="Password is required to save this file.")
'change password to what you want
If myPassword < "123" Then
MsgBox "Password Is Not Correct"
Cancel = True

Else
End If
End Sub


--
Paul B
Always backup your data before trying something new
Using Excel 97 & 2000
Please post any response to the newsgroups so others can benefit from it
** remove news from my email address to reply by email **

"Steve Quiroz" wrote in message
...
Need to know how allow users to enter a password before
they can save changes to the workbook?








All times are GMT +1. The time now is 11:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com