ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   query system username (https://www.excelbanter.com/excel-programming/279544-query-system-username.html)

Kevin Perez

query system username
 
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

Trevor Shuttleworth

query system username
 
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




Roger Whitehead[_3_]

query system username
 
*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




Michael Bond[_3_]

query system username
 
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
.



All times are GMT +1. The time now is 07:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com