返回向指定人员报告的员工列表

时间:2016-10-07 19:25:20

标签: vba outlook-vba

如何通过展望返回向其他员工报告的员工列表。

这将搜索全局地址列表,如果找到用户名,则“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' Object不支持此属性或方法

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

1 个答案:

答案 0 :(得分:1)

olEntry.GetExchangeUser返回一个ExchangeUser对象,但是您将其分配给字符串。

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

获得ExchangeUser对象后,请致电GetDirectReports以获取向给定用户报告的用户列表。