workbook name change password

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
603
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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

AlexM

Board Regular
Joined
Feb 14, 2007
Messages
132
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.
 

lenze

Legend
Joined
Feb 18, 2002
Messages
13,690
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
 

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
603
Office Version
  1. 2019
Platform
  1. Windows
Cool, worked like a champ - many thanks. RB
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,670
Messages
5,838,688
Members
430,563
Latest member
Raeyven

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
Top