disable save unless you are in the list

daffy

Board Regular
Joined
Mar 18, 2009
Messages
113
Hi all
Can you help, i have used the code below. What i am looking to do is turn it around so the array is a list of people that are allowed to save the sheet.

Also needed adding to the code i would like, once someone who is not allowed to save the file, trys and gets the message box saying they are not allowed to save the file. When they click OK the file will close without saving.

Hope you guys can help its driving me mad trying.

Thanks in advanced

don

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim UName As String
Dim NoSave, UFind As Variant
'Get the name of the user logged on the computer
UName = Environ("Username")
'List of names that can NOT use the save function
NoSave = Array("user1", "user2", "user3")
On Error Resume Next
UFind = Application.WorksheetFunction.Match(UName, NoSave, 0)
If Err = 0 Then
Cancel = True
MsgBox ("You are not authorized to save")
End If
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
hi and welcome to the board!!!
Without testing, I think you just need to add the line
Code:
Me.Close

lenze
 
Upvote 0
Try

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim UName As String, MySave
UName = Environ("Username")
MySave = Array("user1", "user2", "user3")
If Not IsNumeric(Application.Match(UName, MySave, 0)) Then
    Cancel = True
    MsgBox "You are not authorized to save"
End If
End Sub
 
Upvote 0
Guys
Thankyou both so much for the fast replys.
Between both of you problem solved.

So wish i had you knowledge

One point can i have it close the whole of excel and not just that file?

Thanks again guys
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,652
Members
448,975
Latest member
sweeberry

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