Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,089
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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
.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the formula to capture username from system into excel she Dave VB logic for excel Excel Discussion (Misc queries) 4 March 1st 11 12:40 PM
What is the function for system to capture the username Dave VB logic for excel Excel Discussion (Misc queries) 4 March 7th 09 07:33 AM
How do I open an Excel file on XP system, saved on a Vista system JLS7 Excel Discussion (Misc queries) 3 December 2nd 08 04:21 AM
Excel 2000 required username and password login for database query ISTech Setting up and Configuration of Excel 0 September 7th 05 01:11 AM
excel causing system to be in low system resource inenewbl Excel Discussion (Misc queries) 0 April 5th 05 04:11 PM


All times are GMT +1. The time now is 06:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"