Consulting

Results 1 to 7 of 7

Thread: Solved: Username from Office/Excel

  1. #1
    VBAX Regular
    Joined
    Oct 2005
    Posts
    33
    Location

    Solved: Username from Office/Excel

    Hi Folks
    I am trying to write a function for the above. It seems simple but I am getting the answer #NAME? with the following code

    [VBA] Function GetName () As String
    GetName = Application.UserName
    End Function
    [/VBA]

    in the cell I wish to have the username, I have typed =GetName. What am I doing wrong?

  2. #2
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    You forgot the parenthesis in your formula..try this:

    =GetName()

    That should do it

    HTH




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  3. #3
    VBAX Regular
    Joined
    Oct 2005
    Posts
    33
    Location
    Thanks for the reply but no, that has no effect. I just know this is going to be something simple. Any other ideas?

  4. #4
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Where have you got your Function - it needs to be in a standard module, not in a sheet or workbook.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Also, it would be better to use

    GetName = Environ("UserName")

    as this will get the login id. Application.Username could be anything.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Regular
    Joined
    Oct 2005
    Posts
    33
    Location
    Thank you all, once again.

    Missing parenthesis and not in a module. Once I changed those it worked a treat. I have checked it on a colleagues machine to ensure it changes to his Office user name and it works just fine.

    Thank you, and in the words of Arnie, I'll be back!


  7. #7
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi guys,

    Too late to help with this one, but I did submit an entry to the KB a while ago to do this. Actually it returns any one of three possibilities: Office username, Computer name or Windows login name.

    Function to return various Environment Names

    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

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