+ Reply to Thread
Results 1 to 10 of 10

Get current user NT group

Hybrid View

  1. #1
    Registered User
    Join Date
    11-29-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    28

    Get current user NT group

    Hi guys,

    I can get user and computer name from Environ,

     (Environ$("Username"))
     (Environ$("Computername"))
    How can i get Current user NT group?

    Thanks,

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Get current user NT group

    What do you wish when a user is member of many groups (this is usually the case!)?

  3. #3
    Registered User
    Join Date
    11-29-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Get current user NT group

    No, i want something like this

    example:

    user 1 belongs to IT
    user 2 belongs to marketing
    user 3 belongs to production

    when i get the username i want to have another field with the group.

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Get current user NT group

    I do not think you understood. A user often belongs to more than one group in Active Directory. In such a case what must the code return?

  5. #5
    Registered User
    Join Date
    11-29-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Get current user NT group

    i want get the group of each user.

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Get current user NT group

    I try one more time. Imagine you have user named Ricardo. He may belong to many NT Groups - All users; Marketing; European colleagues; Systems Committee et cetera. What must the function return as answer?

  7. #7
    Registered User
    Join Date
    11-29-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Get current user NT group

    If he belongs to marketing i want get marketing as his group

  8. #8
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Get current user NT group

    And how will the code know that you want Marketing as the answer and not one of the other groups? What is the logic?

  9. #9
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Get current user NT group

    Sub macro_groups()
    Dim objNetwork, objUser, Usr_groups
    Set objNetwork = CreateObject("WScript.Network")
    strUsername = objNetwork.UserDomain & "/" & objNetwork.Username
    strUsername = Replace(strUsername, "\", "/")
    Set objUser = GetObject("WinNT://" & strUsername & ",user")
    Set Usr_groups = objUser.groups
    End Sub
    That will return all the groups the user is part of to the Usr_groups object variable. I think that normally you would then test if a user is part of a certain group, rather than return which group the user is part of. As Izandol says you would normally be a member of many groups, for example, when I run that on my machine Usr_groups has 13 different items.

  10. #10
    Registered User
    Join Date
    11-29-2013
    Location
    Portugal
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: Get current user NT group

    Thanks all,

    my finish code

    Dim objNetwork, strDomain, strUser, objUser, objGroup, strGroupMemberships
    
    Set objNetwork = CreateObject("WScript.Network")
    strDomain = objNetwork.UserDomain
    strUser = objNetwork.Username
    
    Set objUser = GetObject("WinNT://" & strDomain & "/" & strUser)
    
    For Each objGroup In objUser.Groups
    strGroupMemberships = strGroupMemberships & objGroup.Name & ","
    Next
    
    MsgBox strGroupMemberships

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 06-25-2013, 03:35 PM
  2. Excel User Group
    By Wwcl2010 in forum Excel General
    Replies: 2
    Last Post: 06-07-2013, 01:56 AM
  3. Checking user provided email with current user in document
    By AJRight in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-17-2012, 12:29 PM
  4. Highlight group of cells with value of current cell
    By x65140 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-31-2011, 04:19 PM
  5. Current User
    By obrien2003 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-28-2008, 09:37 AM

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