View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
Mike Fogleman Mike Fogleman is offline
external usenet poster
 
Posts: 1,092
Default Is it Possible to Deny Access except to specified

Right you are! Parentheses wrong order.

Private Sub Workbook_Open()
Dim myArray As Variant
Dim arName As String

arName = "MyUsers"
myArray = ThisWorkbook.Names(arName).RefersToRange.Value

With Application
If IsError(.Match(.UserName, myArray, 0)) Then
MsgBox "You are NOT permitted to Open this File ! !"
Application.DisplayAlerts = False
Application.Quit
Else
End If
End With
End Sub

Mike F
"Sean" wrote in message
oups.com...
Thanks Mike, I'm getting a Syntax error on line
If IsError(.Match(.UserName ), myArray, 0)) Then

Mike Fogleman wrote:

One way is to put the list of users in the workbook somewhere, ie, a
worksheet named "Users" The worksheet can be hidden from view but easily
accessed to update the list without changing the code. Make the list a
Named
Range like "MyUsers" (not the same as a worksheet name). This list will
be
added to an array and will be compared to the .UserName of the person
trying
to open the workbook.

Private Sub Workbook_Open()
Dim myArray As Variant
Dim arName As String

arName = "MyUsers"
myArray = ThisWorkbook.Names(arName).RefersToRange.Value

With Application
If IsError(.Match(.UserName ), myArray, 0)) Then
MsgBox "You are NOT permitted to Open this File ! !",
xlExclamation
Application.DisplayAlerts = False
Application.Quit
Else
End If
End With
End Sub

This is untested, so try it out or modify as needed.
Mike F
"Sean" wrote in message
oups.com...
Is it possible to deny access to open an Excel file except to specified
user?

I assume this code as well as the user access list would go within the
ThisWorksheet. In that on opening the file, it would compare the
Computer user logged in to the list and if "Joe Bloggs" or "Joe Public"
is listed it would allow it to open, otherwise a message "Go Away"
would appear and file would not open

Is this possible, or is it way too advanced?

Thanks