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.
I'd use this instead for the username: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
[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]
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?
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