ophiacus
09-19-2012, 09:28 AM
Hi, I found a simple VBA code to extract the windows ID from the user using the workbook. Now I would like to take this data (example value would be "LZ78408" and unhide VeryHidden worksheets based on the value. NOTE: I would assign a list of possible values to each worksheet in order to determine if the user has viewing priveleges. Can anyone help me with this?
Here is what I'm using in order to get the windows ID;
Option Explicit
'api call forobtaining the
username
Private Declare Function GetUserName&
Lib"advapi32.dll" Alias "GetUserNameA"_(ByVal lpBuffer As String, _nSize As Long)Public Function WindowsUserName() As
String
'
---------------------------------------------
' Function to extract the
name:
'
---------------------------------------------
Dim szBuffer AsString * 100
Dim lBufferLen AsLong
lBufferLen = 100
IfCBool(GetUserName(szBuffer,
lBufferLen)) Then
WindowsUserName = Left$(szBuffer,
lBufferLen - 1)
Else
WindowsUserName =
CStr(Empty)
End If
End Function
Sub GetTheNameAPI()
' Deliver the name via
msgbox
' Uses the api call above & the
Function
MsgBox"Network username is: " &
WindowsUserName
End Sub
Here is what I'm using in order to get the windows ID;
Option Explicit
'api call forobtaining the
username
Private Declare Function GetUserName&
Lib"advapi32.dll" Alias "GetUserNameA"_(ByVal lpBuffer As String, _nSize As Long)Public Function WindowsUserName() As
String
'
---------------------------------------------
' Function to extract the
name:
'
---------------------------------------------
Dim szBuffer AsString * 100
Dim lBufferLen AsLong
lBufferLen = 100
IfCBool(GetUserName(szBuffer,
lBufferLen)) Then
WindowsUserName = Left$(szBuffer,
lBufferLen - 1)
Else
WindowsUserName =
CStr(Empty)
End If
End Function
Sub GetTheNameAPI()
' Deliver the name via
msgbox
' Uses the api call above & the
Function
MsgBox"Network username is: " &
WindowsUserName
End Sub