workbook name change password

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Greetings, I have been using the following code to prevent users from changing the name of a workbook whenever they wanted to. Whenever I wanted to change it (because of a rev. 12 or 13a or something like that) I would just do it by changing the file name on my desktop. Not perfect or really secure I know, but it was easy and simple. There a few drawbacks of course with macro names having to be updated with each revision, or smart alecs changing it my way just to be funny. Is there some code (like a password prompt perhaps) that would allow me to change the name properly from within the app and perhaps even keep people from changing the name from the desktop? Thanks, RB

HTML:
Private Sub WorkBook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim lReply As Long
        If SaveAsUI = True Then
    lReply = MsgBox("Sorry, you are not allowed to save this workbook as a different name.  Do you wish to save it as it's orignal name?", vbQuestion + vbOKCancel)
    Cancel = (lReply = vbCancel)
    If Cancel = False Then Me.Save
        Cancel = True
    End If
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I think there is no way to prevent customer from changing workbook name. It could be copied and renamed in Explorer, also if Application.EnableEvents = false, your macro will not be called.
 
Upvote 0
Give this a try
Code:
Private Sub WorkBook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If SaveAsUI = True Then
    rspn = InputBox("Enter Password to save")
        If rspn <> "password" Then
            MsgBox "Invalid Password"
            Cancel = True
        End If
    End If
End Sub

lenze
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,239
Members
448,951
Latest member
jennlynn

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