I am trying to code a workbook that functions differently for specified users. I want the code to recognize the network UserID of the person accessing the workbook. The workbook opens to a specified worksheet for those users and hyperlinks within the workbook redirect differently for the specified users.
I have attached a workbook to play with.
Here is some wrong code for the UserID. I read over the a couple of the UserLog entries, but couldn’t discern how to leverage them.
Private Sub Workbook_Open()
Dim strUserName As String
If strUserName = name1, name2 or name3 Then
Worksheets(“SpecificUser”).Activate
End If
Worksheets(“GeneralUser”).Activate
End Sub
I did find some code that creates a UserLog within MS Access:
Private Declare Function apiGetUserName Lib “advapi32.dll” Alias “GetUserNameA” _ (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
On Error GoTo fOSUserName_Err
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen – 255
lngX = apiGetUserName(strUserName, lngLen – 1)
If lngX 0 Then
fOSUserName = “”
End If
fOSUserName_Exit:
Exit Function
fOSUserName_Err:
MsgBox Error$
Resume fOSUserName_Exit
End Function
Either way, I would like the object hyperlink (Return) in the Data1 and Data2 worksheets to hyperlink to the SpecificUser worksheet when the specified users are in the workbook and go to the GeneralUser worksheet for everyone else.
Thanks
Amy