Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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
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
Capturing Formatting with VLookup kalandine Excel Discussion (Misc queries) 1 February 25th 10 04:32 AM
Capturing Top 5 Performers Questor Excel Worksheet Functions 5 April 18th 09 11:33 PM
capturing all of the data jimbo Excel Worksheet Functions 7 July 27th 08 06:10 PM
Capturing Date Larry Fish via OfficeKB.com New Users to Excel 4 September 27th 06 01:40 PM
Capturing First Change In A Cell carl Excel Worksheet Functions 4 February 21st 06 01:21 PM


All times are GMT +1. The time now is 10:01 PM.

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

About Us

"It's about Microsoft Excel"