Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 5 of 5

Thread: using system variables

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Sheffield, UK
    Posts
    253
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    When someone logs onto the network where I work, a system variable called FNAM holds their name. I can get at this in DOS, but is there any way I can get to it in Excel?

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Newcastle, UK
    Posts
    1,174
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-05-07 07:26, philR wrote:
    When someone logs onto the network where I work, a system variable called FNAM holds their name. I can get at this in DOS, but is there any way I can get to it in Excel?
    Do you mean their NT Username?

    if yes, copy this into a module:

    Option Explicit
    ' This is used by GetUserName() to find the current user's
    ' name from the API
    Declare Function Get_User_Name Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, _
    nSize As Long) As Long


    Function GetUserName() As String
    Dim lpBuff As String * 25

    Get_User_Name lpBuff, 25
    GetUserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
    End Function

    hope this helps.
    "Have a good time......all the time"
    Ian Mac

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Location
    Sheffield, UK
    Posts
    253
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Wow! That is a very cool piece of code! It does almost what I want, but it is returning "smithj" (which if you type "SET" in DOS is the system variable UNAM) wheras what I want is "John Smith", which is the system variable FNAM. This code must be very close to what I need, but I don't know how to modify it. Incidentally, we are networked on Windows 95, soon to be upgraded to 2000.
    Thanks for your help so far,

    Phil

  4. #4
    Board Regular
    Join Date
    May 2002
    Location
    Gothenburg, Sweden
    Posts
    74
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try

    s=Environ("FNAM")


    /Niklas Jansson

  5. #5
    Board Regular
    Join Date
    Feb 2002
    Location
    Sheffield, UK
    Posts
    253
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Excellent! That works perfectly. Thank you

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •