+ Reply to Thread
Results 1 to 20 of 20

Active Directory Data Using Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Active Directory Data Using Macro

    Hi Everyone,
    Got answers from my previous inquiries and Im back again to seek for more help ^^

    This time around what i want to do is to be able to pull all the groups a LAN ID is a member of.
    It's like, I will just put the LAN ID on one cell and when I run a Macro, it will return the list of Groups this ID is a member of.


    I have gotten help from romperstomper on my previous post.
    Hope to get help again.
    (http://www.excelforum.com/excel-prog...ing-macro.html)


    Thanks again
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro (Part2)

    I'm sure this can be done.
    Last edited by Vincent.Eymard; 11-08-2010 at 10:09 PM.

  3. #3
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro (Part2)

    Looking forward to your Inputs ^^
    Thanks in advance.

  4. #4
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro (Part2)

    Please please please.. hope someone out there could help..

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Active Directory Data Using Macro (Part2)

    You'd better look at the attachment you posted.



  6. #6
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro (Part2)

    Quote Originally Posted by snb View Post
    You'd better look at the attachment you posted.
    Hi snb. I viewed the attachment and looks okay.
    I'm not sure what I'm missing..

  7. #7
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro (Part2)

    I hope to get luck and find help today ^^

  8. #8
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro (Part2)

    Still no luck with this one.. (

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Active Directory Data Using Macro (Part2)

    Try this:
    
    Option Explicit
    Sub GetGroupData()
        GetGroupMembership Sheet1.Range("D2").Value, Sheet1.Range("A8")
    End Sub
    
    Sub GetGroupMembership(strUser As String, rngOut As Range)
    
    Dim objConnection, objCommand, objRecordSet, objUser, objRootDSE, objMember
    Dim strLine, arrGroup
    
    Set objConnection = CreateObject("ADODB.Connection")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    
    Set objCommand = CreateObject("ADODB.Command")
    objCommand.ActiveConnection = objConnection
    
    Set objRootDSE = GetObject("LDAP://RootDSE")
    objCommand.CommandText = "SELECT aDSPath FROM 'LDAP://" & objRootDSE.Get("defaultNamingContext") & _
                                "' WHERE objectClass='user' And name='" & strUser & "'"
    Set objRootDSE = Nothing
    
    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Timeout") = 600
    objCommand.Properties("Cache Results") = False
    
    Set objRecordSet = objCommand.Execute
    rngOut.CurrentRegion.Offset(1).ClearContents
    While Not objRecordSet.EOF
        Set objUser = GetObject(objRecordSet.Fields("aDSPath"))
        For Each objMember In objUser.GetEx("memberOf")
            strLine = Mid(objMember, 4, 330)
            arrGroup = Split(strLine, ",")
            rngOut.Value = arrGroup(0)
            Set rngOut = rngOut.Offset(1)
        Next
        ' Additional section to find the primary group.
        If objUser.primaryGroupID = 513 Then
           rngOut.Value = "Domain Users"
        Else
            If objUser.primaryGroupID = 515 Then
               rngOut.Value = "Domain Computers"
            Else
                rngOut.Value = "Maybe a Domain Controller"
            End If
        End If
    
        Set objUser = Nothing
        objRecordSet.MoveNext
    Wend
    
    objConnection.Close
    Set objRecordSet = Nothing
    Set objCommand = Nothing
    Set objConnection = Nothing
    
    End Sub
    Everyone who confuses correlation and causation ends up dead.

  10. #10
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro (Part2)

    Hi again romperstomper!
    Thank you very much for your help again.
    Tried the script but when I click the button nothing seems to happen.
    Not sure what to do
    Last edited by romperstomper; 11-11-2010 at 03:34 AM. Reason: Remove quote

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Active Directory Data Using Macro (Part2)

    Did you assign the getGroupData macro to the button? If not, then no it won't do anything.

    Please don't quote entire posts when replying to them - it serves no purpose.

  12. #12
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro (Part2)

    Hi again romperstomper,
    Yup I assigned the button to the macro getGroupData, but when i click nothing seems to happen.
    Unlike with the other script that you helped me with.

  13. #13
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Active Directory Data Using Macro (Part2)

    Then I guess the login id you entered is incorrect, because the script works fine for me.

  14. #14
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro (Part2)

    I provided my own logon ID.
    Hmnnn... Still trying to figure out what might be the problem..

  15. #15
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro (Part2)

    It's even more weird this time, when I use a LAN ID such as myself I dont get any result, but when I used the generic ID "guest" there was a result (attached).
    Hope someone can help.

    Thanks again.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro (Part2)

    Still couldn't get this to work. Hope somebody could help me out.
    Thanks in advance. ^^

  17. #17
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro (Part2)

    Hope to get help.
    I haven't solved it still, when I use a LAN ID such as myself I dont get any result, but when I used the generic ID "guest" there was a result (attached).
    Hope someone can help.

    Thanks again.
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro (Part2)

    Still looking and seeking for help..

  19. #19
    Registered User
    Join Date
    10-13-2010
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    82

    Re: Active Directory Data Using Macro (Part2)

    Anyone got the chance to look at this? ^^
    Hope to find help.

    Thanks

  20. #20
    Registered User
    Join Date
    09-18-2012
    Location
    Syracuse
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Active Directory Data Using Macro (Part2)

    Hi Vincent,
    Sorry I know it has been along time since this post. I did get the script working right however. I entered the ID in the same format as it was in the first extraction. For example the ID's came back as Doe, John. So if you enter it in the same format in the second extraction it does work. Your other option would be to change the line below.

    objCommand.CommandText = "SELECT aDSPath FROM 'LDAP://" & objRootDSE.Get("defaultNamingContext") & _
    "' WHERE objectClass='user' And name='" & strUser & "'"

    to

    objCommand.CommandText = "SELECT aDSPath FROM 'LDAP://" & objRootDSE.Get("defaultNamingContext") & _
    "' WHERE objectClass='user' And SAMAccountName='" & strUser & "'"

    Then you can use jdoe rather then doe, John

    Jlynn001

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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