protectedsaving of file

wmtsub

Active Member
Joined
Jun 20, 2018
Messages
322
is there someway that i can ran a macro or a script or an object thast would not permit anyone to save my file unless they have a password other than protecting the file in wiondows? I wonder if that can be done from insiew the workbook.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
So going in a slightly different direction. Can I check for a specific user and grant them right's and any other simply exit the file?

Will this work?


'Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Application.UserName = "user name" Then ActiveWorkbook.Save else exit
End Sub
 
Upvote 0
So going in a slightly different direction. Can I check for a specific user and grant them right's and any other simply exit the file?

Will this work?


'Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Application.UserName = "user name" Then ActiveWorkbook.Save else exit
End Sub
I'd use this instead for the username:
Code:
[COLOR=#454545][FONT='inherit']Function UNameWindows() As String
[/FONT][/COLOR][COLOR=#454545][FONT='inherit'][FONT='inherit']    UNameWindows = Environ("USERNAME")[/FONT][/FONT][/COLOR]
[COLOR=#454545][FONT='inherit']End Function[/FONT][/COLOR]
 
Upvote 0
I might need some more direction. If I use the code given above how di I grant that user rights to save the file - or how do I exclude everyone else? And which way makes more sense?


Function UNameWindows()
As String
UNameWindows = Environ("USERNAME")

End Function
 
Upvote 0
I might need some more direction. If I use the code given above how di I grant that user rights to save the file - or how do I exclude everyone else? And which way makes more sense?

That would depend on your preference. I personally would choose the option that grants or denies access to the fewest amount of people. For example, it would be much easier if you granted access to only 1 or 2 people, rather than denying access to an enumerated list. But if your access list is larger than your deny list, then it's easier to just deny access via a blacklist.

If I were you, I'd look into maintaining a read-only list (blacklist or whitelist, whichever is smaller). Then just check your username against that list, and grant or deny accordingly.
 
Upvote 0
well for the sake of getting this started have you an example perhaps of how I would grant only one person rights? I am unsure of how to proceed.
 
Upvote 0
First, create the whitelist UAL (user access list) text file. In that file, enter all the usernames that are allowed to save. Then use this code:

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If InStr(Whitelist("C:\path\to\UAL.txt"), UNameWindows) <> 0 Then
        MsgBox "Approved"
    End If
End Sub
Function UNameWindows() As String
    UNameWindows = Environ("USERNAME")
End Function
Function Whitelist(TxtPath As String)
    Dim TextFile As Integer
    Dim FilePath As String
    Dim FileContent As String
    
    FilePath = TxtPath
    TextFile = FreeFile
    Open FilePath For Input As TextFile
    FileContent = Input(LOF(TextFile), TextFile)
    Whitelist = FileContent
    Close TextFile
End Function
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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