Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
How can I return the system username either in VBA or a function? I've written a macro to enable several different users to input data. I want to provide a measure of security so that only select users can activate the macro. Thanks. Kevin |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Kevin
Private Declare Function apiGetUserName Lib "advapi32.dll" _ Alias "GetUserNameA" (ByVal lpBuffer As String, nsize As Long) As Long Function fOSUserName() As String ' Returns the network login name Dim lngLen As Long, lngX As Long Dim strUserName As String strUserName = String$(254, 0) lngLen = 255 lngX = apiGetUserName(strUserName, lngLen) If lngX < 0 Then fOSUserName = Left$(strUserName, lngLen - 1) Else fOSUserName = "" End If End Function Sub GetUserNameTest() MsgBox fOSUserName End Sub Regards Trevor "Kevin Perez" wrote in message ... Hello, How can I return the system username either in VBA or a function? I've written a macro to enable several different users to input data. I want to provide a measure of security so that only select users can activate the macro. Thanks. Kevin |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
*If* they have their name in the User Details dection of Tools, Options -
then Application.UserName For network login details, you'll need an API call. There is one for NT (Can't find it right now - don't use NT), not so sure about others. HTH Roger Shaftesbury (UK) "Kevin Perez" wrote in message ... Hello, How can I return the system username either in VBA or a function? I've written a macro to enable several different users to input data. I want to provide a measure of security so that only select users can activate the macro. Thanks. Kevin |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Kevin
I use the following function to achieve the same as you are looking for.... I then have an "auto_open" macro which acts differently depending on the username which is returned I got this from another user on the newsgroup HTH Michael Bond Private Declare Function GetUserName Lib "advapi32.dll" _ Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Private Function ReturnUserName() As String ' returns the Domain User Name Dim rString As String * 255, sLen As Long, tString As String tString = "" On Error Resume Next sLen = GetUserName(rString, 255) sLen = InStr(1, rString, Chr(0)) If sLen 0 Then tString = Left(rString, sLen - 1) Else tString = rString End If On Error GoTo 0 ReturnUserName = (Trim(tString)) End Function -----Original Message----- Hello, How can I return the system username either in VBA or a function? I've written a macro to enable several different users to input data. I want to provide a measure of security so that only select users can activate the macro. Thanks. Kevin . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
What is the formula to capture username from system into excel she | Excel Discussion (Misc queries) | |||
What is the function for system to capture the username | Excel Discussion (Misc queries) | |||
How do I open an Excel file on XP system, saved on a Vista system | Excel Discussion (Misc queries) | |||
Excel 2000 required username and password login for database query | Setting up and Configuration of Excel | |||
excel causing system to be in low system resource | Excel Discussion (Misc queries) |