none
VBA to user to a exchange distribution list RRS feed

  • Question

  • I am trying add users to an exchange distribution list. However it throws me an error 'Permission denied'. I am creating the active directory connection object using the uid/ pwd of the user who is the owner of the DL i.e. the DL lists him as the owner.

    I am clueless about what I am missing here. I having been searching for long but have not got any breakthrough. The code is pasted below. The domain name 'abc' and the domain in the e-mail 'xyz' are different though both are internally mapped. That is the format adopted in my organization

    Const AD_DOMAIN_NAME = "abc.com"

    strGroup = "group display name"

    strEmail = "usermail@xyz.com"

    strGroupPath = Get_AD_Object_Path("SELECT ADsPath FROM 'LDAP://" & AD_DOMAIN_NAME & "' WHERE objectClass='group' AND Name='" & strGroup & "'")

    strUserPath = Get_AD_Object_Path("SELECT ADsPath FROM 'LDAP://" & AD_DOMAIN_NAME & "' WHERE objectClass='user' AND objectCategory='Person' AND Mail='" & Trim(strEmail) & "'")

    Set objGroup = GetObject(strGroupPath)

    Set objMember = GetObject(strUserPath)

    objGroup.Add strUserPath

    objGroup.SetInfo

    Set objGroup = Nothing


    Function Get_AD_Object_Path(strQuery)

        Dim rsDetails
        Set rsDetails = CreateObject("ADODB.Recordset")
        With rsDetails
            .ActiveConnection = "Provider=ADSDSOObject"
            .Source = strQuery
            .CursorType = 0
            .CursorLocation = 2
            .LockType = 1
            .Open
        End With
        If (Not rsDetails.BOF) And (Not rsDetails.EOF) Then
            Get_AD_Object_Path = rsDetails.Fields("ADsPath").Value
        Else
            Get_AD_Object_Path = "Not Found"
        End If
        Set rsDetails = Nothing

    End Function

    Wednesday, December 24, 2014 2:36 AM

All replies