2016-10-07 37 views
0

如何返回通过Outlook向其他员工报告的员工列表。返回向指定人员报告的员工列表

这将搜索全局地址列表,如果找到用户名'user'等于交换用户对象(我认为)。

当我运行它时,它说用户是一个无效的限定符,但是当我查找它时,您应该调用交换用户对象上的GetDirectReports函数。

Public olApp As Object 
Public olNameSpace As Object 

Dim Person As cEmployee 
Set Person = New cEmployee 
Dim Emp As cEmployee 

Dim user As String 
Dim olEntry 
Dim userCollection As collection 
Set olApp = CreateObject("Outlook.Application") 
Set olNameSpace = olApp.GetNameSpace("MAPI") 
Set olGal = olNameSpace.GetGlobalAddressList 
Set userCollection = New collection 

For Each OlEntry In olGal.AddressEntries 
    If olEntry.name = "Manager's Name" Then 
     user = olEntry.GetExchangeUser() 
     Exit For 
    End If 
Next olEntry 

Dim iter 
For Each iter In olEntry.GetDirectReports() 
    Set Emp = new cEmployee 
    userCollection.Add Emp 
Next iter 

我想要一个cEmployee对象的集合向指定的管理器报告。

我得到的错误是

运行时错误“438” 对象不支持此属性或方法

Option Explicit 
Private pName As String 
Private pMail As String 
Private pUserName As String 
Private pPhone As String 

Public Property Get name() As String 
    name = pName 
End Property 

Public Property Let name(user As String) 
    pName = user 
End Property 

Public Property Get mail() As String 
    mail = pMail 
End Property 
Public Property Let mail(email As String) 
    pMail = email 
End Property 

Public Property Get userName() As String 
    userName = pUserName 
End Property 
Public Property Let userName(name As String) 
    pUserName = name 
End Property 

Public Property Get phone() As String 
    phone = pPhone 
End Property 

Public Property Let phone(number As String) 
    pPhone = number 
End Property 
+0

'cEmployee'的类代码在哪里?最后一个'For'循环看起来好像只是将一个空对象添加到一个集合中 - 你想在那里实现什么? –

+0

已添加课程代码 –

+0

我是否需要cEmployee类的构造函数?对不起,这是第一次使用vba –

回答

1

olEntry.GetExchangeUser返回ExchangeUser对象,但你要分配它到一个字符串。

Dim user As Object 
... 
set user = olEntry.GetExchangeUser() 

一旦有ExchangeUser对象,调用GetDirectReports让谁给定的用户报告的用户列表。

+0

哦,你的权利......谢谢! –

+0

所以每个'iter'都是交换用户? –

+0

是的,会的。 –