Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Capturing user name
I am trying to keep a running log of every user who opens a workbook. On
startup, I'm running a macro that includes the "Application.UserName" command to get the user name. However, many users of the workbook have Excel set up so that the username returned by "Application.UserName" is simply "Registered User". The "Registered User" seems to be an Excel artifact only, based on what is entered in "Tools Options General User name" Is there a way in VB to get a "lower-level" user name, from Windows itself maybe? Because even on the machines that have "Registered User" in Excel, the actual person's name can be found in Windows (2000) "My Computer" properties. I would like to somehow bypass Excel's "Registered User" value and get the person's real user name as set in Windows. TIA. -SF |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Capturing user name
This came from a previous post by Chip Pearson. You can probably find more
info on his website http://www.cpearson.com/excel.htm Paul Option Explicit Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" ( _ ByVal lpBuffer As String, nSize As Long) As Long Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" ( _ ByVal lpBuffer As String, nSize As Long) As Long Sub AAA() Dim CName As String Dim UName As String Dim CL As Long Dim UL As Long CName = String(255, " ") UName = String(255, " ") CL = 255 UL = 255 GetUserName UName, UL GetComputerName CName, CL UName = Left(UName, UL - 1) ' yes, -1. Thanks, MS, for consistency CName = Left(CName, CL) MsgBox "Username is: " & UName MsgBox "Computer name is: " & CName End Sub "Syed Faisal" wrote in message ... I am trying to keep a running log of every user who opens a workbook. On startup, I'm running a macro that includes the "Application.UserName" command to get the user name. However, many users of the workbook have Excel set up so that the username returned by "Application.UserName" is simply "Registered User". The "Registered User" seems to be an Excel artifact only, based on what is entered in "Tools Options General User name" Is there a way in VB to get a "lower-level" user name, from Windows itself maybe? Because even on the machines that have "Registered User" in Excel, the actual person's name can be found in Windows (2000) "My Computer" properties. I would like to somehow bypass Excel's "Registered User" value and get the person's real user name as set in Windows. TIA. -SF |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Capturing user name
Is the environment variable "username" set to the correct user? I'm not sure
if this depends on how the PC was setup in your organization. Might try MsgBox Environ$("username") |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Capturing user name
Public UserName As String
Private Sub Workbook_Open() WhoIsThis UserName end sub Sub WhoIsThis(UserName As String) Dim UserLength As Long UserName = String(255, " ") UserLength = 255 GetUserName UserName, UserLength UserName = Left(UserName, UserLength - 1) End Sub Public Declare Function GetUserName Lib "advapi32.dll" _ Alias "GetUserNameA" (ByVal lpBuffer As String, _ nSize As Long) As Long -----Original Message----- I am trying to keep a running log of every user who opens a workbook. On startup, I'm running a macro that includes the "Application.UserName" command to get the user name. However, many users of the workbook have Excel set up so that the username returned by "Application.UserName" is simply "Registered User". The "Registered User" seems to be an Excel artifact only, based on what is entered in "Tools Options General User name" Is there a way in VB to get a "lower-level" user name, from Windows itself maybe? Because even on the machines that have "Registered User" in Excel, the actual person's name can be found in Windows (2000) "My Computer" properties. I would like to somehow bypass Excel's "Registered User" value and get the person's real user name as set in Windows. TIA. -SF . |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Capturing user name
Syed,
Here's a simple little function to get it Public Declare Function GetUserName Lib "advapi32.dll" _ Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ nSize As Long) As Long Public Function UserName() As String Dim sName As String * 256 Dim cChars As Long cChars = 256 If GetUserName(sName, cChars) Then UserName = Left$(sName, cChars - 1) End If End Function -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Syed Faisal" wrote in message ... I am trying to keep a running log of every user who opens a workbook. On startup, I'm running a macro that includes the "Application.UserName" command to get the user name. However, many users of the workbook have Excel set up so that the username returned by "Application.UserName" is simply "Registered User". The "Registered User" seems to be an Excel artifact only, based on what is entered in "Tools Options General User name" Is there a way in VB to get a "lower-level" user name, from Windows itself maybe? Because even on the machines that have "Registered User" in Excel, the actual person's name can be found in Windows (2000) "My Computer" properties. I would like to somehow bypass Excel's "Registered User" value and get the person's real user name as set in Windows. TIA. -SF |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Capturing Formatting with VLookup | Excel Discussion (Misc queries) | |||
Capturing Top 5 Performers | Excel Worksheet Functions | |||
capturing all of the data | Excel Worksheet Functions | |||
Capturing Date | New Users to Excel | |||
Capturing First Change In A Cell | Excel Worksheet Functions |