1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

info

Discussion in 'Business Applications' started by 997df, Jan 28, 2007.

Thread Status:
Not open for further replies.
  1. 997df

    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
     
  2. Rollin_Again

    Rollin_Again

    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
     
  3. 997df

    997df Thread Starter

    Joined:
    Jan 28, 2007
    Messages:
    2
    Thank You
     
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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/539040

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice