• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

restricted access

Hi All,

Need to know if we have any before workbook open sort of event or trick....

I have a file that I want to restricted to specific user....and any other user tries to open that file he should be restricted....he should not be even see any of the sheets....I have following coding which works well but other users are able to see the sheet...Please help..

Code:
Private Sub Workbook_Activate()

Dim bz As Boolean
 
  'MsgBox Environ("username")

 
  With ThisWorkbook
  bz = Environ("username") = "S83" Or Environ("username") = "S81" Or _
  Environ("username") = "H41"
 
  If bz = False Then
  MsgBox Environ("username") & " you are not authorized to open this file"
  ThisWorkbook.Close
  End If
  End With

End Sub
 
Last edited by a moderator:
Hi, sandysharma!

Before opening a file there's no information about it, so... nothing could be done.

This are the events and its sequence at open time:
http://pixcels.nl/events-in-workbooks/

So anything you want to do, you must do it in the Open event code section and not in the Activate one.

BTW, checking against environment variable Username it doesn't guarantee you that the authorized person is opening the file, it only says that it's opening from a computer in which that user is logged in. Instead of that why not adding an open password and give it to that person?

Regards!
 
Back
Top