View Single Post
  #16   Report Post  
Posted to microsoft.public.excel.programming
Charles Chickering Charles Chickering is offline
external usenet poster
 
Posts: 272
Default Is it Possible to Deny Access except to specified

Sean, change Application.Quit to
ThisWorkbook.Close False
or if you want to get really fancy, this:
If Workbooks.Count = 1 Then
'Only this book is open go ahead and quit
Application.Quit
Else
'Must be something else open
ThisWorkbook.Close False
End If

Also as Dave has pointed out, have you experimented with what happens to
your workbook when you open it and select "Disable Macros"? I would either
change the file permissions from Windows or put the file in a password
protected zip file.

--
Charles Chickering

"A good example is twice the value of good advice."


"Sean" wrote:

Well I'm pretty pleased with the attached which will open at a Blank
sheet if its a non-permitted user, otherwise it opens on an info sheet.
One slight problem is that if its a non-permitted user the whole Excel
application closes, which I wouldn't want if other active files are
open. How would I just close the file I'm attempting to open?

Private Sub Workbook_Open()
Application.ScreenUpdating = False
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
sh.Select
Application.GoTo Reference:=sh.Range("a1"), Scroll:=True
Next sh
ThisWorkbook.Sheets("Input").Select
Application.ScreenUpdating = True

Dim myArray As Variant
Dim arName As String


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


With Application
If IsError(.Match(.UserName, myArray, 0)) Then
ThisWorkbook.Sheets("Blank Sheet").Select

MsgBox "You are NOT Permitted to access this File " & vbNewLine & _
" " & vbNewLine & _
"Please Contact " & vbNewLine & _
" " & vbNewLine & _
"Joe Bloggs at " & vbNewLine & _
" " & vbNewLine & _
"ABC Group +0019 66200000"
Application.DisplayAlerts = False
Application.Quit
Else
End If
End With
ThisWorkbook.Sheets("Input").Select

End Sub







Mike Fogleman wrote:

You're right Dave, the best we can do is keep honest people honest.

Mike F
"Dave Peterson" wrote in message
...
I don't think there is any workaround to the user disabling macros.

Once the workbook is opened, the user can show hidden sheets and unprotect
any
worksheet (or the workbook).

And if the user knows how to use google, the user can find a way to bypass
the
project protection.

If you really have sensitive data, don't put it into excel. If you have
to put
it into excel, don't share it with anyone you don't trust.

Mike Fogleman wrote:

Dave has a valid point. There is a work-around for those who disable
macros,
using a "Splash" sheet, if you're interested.

Mike F
"Dave Peterson" wrote in message
...
Not really.

Any suggestion will probably include macros. Macros can be disabled
and
your
information would be available to anyone who had the file.



Sean wrote:

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

--

Dave Peterson

--

Dave Peterson