我有我组织中所有员工的员工ID列表。我希望Excel VBA代码获取详细信息,例如名字,姓氏,指定联系人编号和部门。
别名是员工ID。因此,代码应将Employee ID作为别名,并如上所述在Outlook中搜索相应的详细信息。
我在网上找到了一个宏并将其修改为我的要求:
Sub tgr()
Dim appOL As Object
Dim oGAL As Object
Dim oContact As Object
Dim oUser As Object
Dim UserIndex As Long
Dim i As Long
Dim j As Integer
Set appOL = CreateObject("Outlook.Application")
Set oGAL = appOL.GetNamespace("MAPI").AddressLists("/Name of the Distribution List/").AddressEntries
On Error Resume Next
For j = 2 To Application.WorksheetFunction.CountA(Columns(1))
For i = 1 To oGAL.Count
Set oContact = oGAL.Item(i)
If oContact.AddressEntryUserType = 0 Then
Set oUser = oContact.GetExchangeUser
If UCase(oUser.FirstName) = UCase(Range("A" & j).Value) And UCase(oUser.LastName) = UCase(Range("B" & j).Value) Then
Range("c" & j).Value = oUser.Alias
Range("D" & j).Value = oUser.JobTitle
Range("E" & j).Value = oUser.Department
Range("F" & j).Value = oUser.ManagerName
i = oGAL.Count
End If
End If
Next i
Next j
Set oGAL = Nothing
Set oContact = Nothing
Set oUser = Nothing
End Sub
该代码有效,但问题在于它每次都会检查地址列表中的所有项目以搜索每个项目。这需要更多时间。
有没有一种方法可以通过广泛搜索而不是查看地址列表中的每个项目并进行比较来简化它。类似于Addresslist.find。好吧,只有在联系人文件夹中搜索地址列表且没有FIND属性的情况下,适当的查找才有效。
别名是否与Windows登录别名相同?尝试Namespace.ResolveName-GAL提供程序将基于登录别名进行解析。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句