Thread: View by User
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Eric G Eric G is offline
external usenet poster
 
Posts: 30
Default View by User

The links below show how to use Windows API calls to get either the full name
or the login name of the user. You can put a call to one of these routines
in your workbook_open event and then compare that to your pre-defined list of
users to determine which sheets should be hidden or not.

http://www.mvps.org/access/api/api0066.htm
http://www.mvps.org/access/api/api0008.htm

Here is some code to help you get started. First, paste the code from the
above links into a regular code module in your workbook. Then, in the
Workbook module, enter the code below. This demonstrates how to get either
the login name or the full user name, along with some psuedo-code for setting
views based on which user has the file opened.

Private Sub Workbook_Open()
Dim theUser As String
'
' Use one or the other as required...
'
theUser = fGetFullNameOfLoggedUser()
MsgBox theUser
'
theUser = fOSUserName()
MsgBox theUser
'
Select Case theUser
Case "simpshj" ' login ID example
ActiveWorkbook.Sheets("Sheet1").Visible = True
ActiveWorkbook.Sheets("Sheet2").Visible = False
Case "Homer J Simpson" ' full name example
ActiveWorkbook.Sheets("Sheet1").Visible = True
ActiveWorkbook.Sheets("Sheet2").Visible = False
Case Else ' default view
ActiveWorkbook.Sheets("Sheet1").Visible = False
ActiveWorkbook.Sheets("Sheet2").Visible = True
End Select
'
End Sub

WARNING: I just thought of this. You may not be able to alter the
structure of the workbook (i.e. showing and hiding tabs) if it is a shared
file. You'll just have to experiment.

HTH,

Eric

"Pam M" wrote:

I have a workbook that will be shared that contains several worksheets.
Depending on the user, I want different sheets hidden from view upon opening
the workbook. Is there an easy way to do this?