info

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

997df

Thread Starter
Joined
Jan 28, 2007
Messages
2
Hi
Iam using excel 2002 xp box!
What I want to is to get the name of the person loged in windows.
so I can print it with the spreadsheet data.

How?

Thanks
 
Joined
Sep 4, 2003
Messages
4,912
In some cases you can obtain the info by using the following VBA code within Excel

Code:
Dim vUser As String

vUser = Application.UserName
Msgbox(vUser)
The method above is unreliable since many time the log in user name may or may not be the name that is returned by Application.User

A more reliable method is to use a Windows API call to return the name of the user that is logged into Windows. Record a blank macro and copy and paste the code below into the module. Then run the macro named "UserName" to obtain the name of the active user. Just replace the messagebox with the code to insert into a cell of your choice.

Code:
Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) _
  As Long

Public Sub UserName()

    Dim Buffer As String * 100
    Dim BuffLen As Long
    Dim vUserName As String
    BuffLen = 100
    GetUserName Buffer, BuffLen
    vUserName = Left(Buffer, BuffLen - 1)
    MsgBox (vUserName & " is currently logged in")

End Sub
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top