+ Reply to Thread
Results 1 to 6 of 6

Parse first name & surname from Windows logon name (Environ("UserName")

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Cool Parse first name & surname from Windows logon name (Environ("UserName")

    I was wondering if it would be possible to parse out an individuals first name & surname from their Windows logon name.

    Obtaining the Windows logon name is easily done (
    Please Login or Register  to view this content.
    ) so the only real difficulty is:
    1. Correctly parse names from as many variations of a user name as possible (i.e. names separated with a full stop, names separated with an underscore etcetcera) and
    2. Ignore most standard non-individual names (e.g. Administrator, Admin, Accounts, Sales etcetcera)

    A quick google search throws up many results on parsing names from cells but these don't have a good success rate on actual user name formats. Below is what I have so far.

    Please Login or Register  to view this content.
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Parse first name & surname from Windows logon name (Environ("UserName")

    I think you've set yourself a task there..

    Part of the solution may be to count the number of words in the name as a first step... You could modify the function to include seperators..

    Please Login or Register  to view this content.
    Elegant Simplicity............. Not Always

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Parse first name & surname from Windows logon name (Environ("UserName")

    Quote Originally Posted by AndyLitch View Post
    I think you've set yourself a task there..
    True. I enjoy the challenge though.

    Quote Originally Posted by AndyLitch View Post
    Part of the solution may be to count the number of words in the name as a first step... You could modify the function to include seperators..
    Thank you for the suggestion. I'm looking into it now. (I'm trying to think of a solution to handle when the first and last name don't have a separator. e.g. JohnSmith )

  4. #4
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Parse first name & surname from Windows logon name (Environ("UserName")

    I am now up to this (see code below). It's not perfect. If you try it and your user name is not parsed by the function, I would be interested in knowing what it is so I can tweak it further.

    Please Login or Register  to view this content.

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Parse first name & surname from Windows logon name (Environ("UserName")

    if the users are on an active directory domain you could just query the domain controller for the user name
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  6. #6
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Parse first name & surname from Windows logon name (Environ("UserName")

    Quote Originally Posted by JosephP View Post
    if the users are on an active directory domain you could just query the domain controller for the user name
    Appreciate the suggestion. However I want this function as versatile as possible - work on non-networked PCs for e.g.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1