繁体   English   中英

Outlook 2013 VBA 从全局地址列表中获取所需数据

[英]Outlook 2013 VBA Getting required data from Global Address List

我正在使用 Outlook VBA 代码通过全局地址列表中的唯一职位查找特定的电子邮件地址。 我有下面的代码,但我不确定如何识别特定的电子邮件地址。我将其用作函数,以便可以在子例程中调用它。

我一直收到错误“未设置对象变量或块变量”,但我不知道如何在代码中进行编辑以消除错误。 我在这一行收到错误:“Set olUser = olAddressEntry.GetExchangeUser”。

Function GALEmail(specificTitle As String) As String

Dim olNs As Outlook.NameSpace
Dim olGAL As Outlook.AddressEntries
Dim olAddressEntry As Object
Dim olUser As Object
Dim sEmail As String
Dim i As Long
Dim GetCurrentItem As Object

Set olNs = Application.GetNamespace("MAPI")
Set olGAL = olNs.AddressLists("Global Address List").AddressEntries
Set GetCurrentItem = Application.ActiveInspector.currentItem
Set olUser = Nothing

'On Error Resume Next
With GetCurrentItem
    For i = 1 To olGAL.Count
        Set olAddressEntry = olGAL.Item(i)
        Set olUser = olAddressEntry.GetExchangeUser
        MsgBox olUser
        sEmail = olGAL.Item(i).Title

        If sEmail = specificTitle Then
            Set olUser = olAddressEntry.GetExchangeUser
            Debug.Print olUser.Email1Address
        End If
    Next i
End With

End Function

任何帮助将不胜感激!!

我已经想出了如何获得带有职位的电子邮件地址,如下所示:

Function GALEmail(specificTitle As String) As String

Dim olNs As Outlook.NameSpace
Dim olGAL As Object
Dim olAddressEntry As Object
Dim olUser As Object
Dim sEmail As String
Dim i As Long
Dim GetCurrentItem As Object

Set olNs = Application.GetNamespace("MAPI")
Set olGAL = olNs.AddressLists("Global Address List").AddressEntries
Set GetCurrentItem = Application.ActiveInspector.currentItem

'On Error Resume Next
With GetCurrentItem
    For i = 1 To olGAL.Count
        Set olAddressEntry = olGAL.Item(i)

        If olAddressEntry.AddressEntryUserType = 0 Then
        Set olUser = olAddressEntry.GetExchangeUser
        sEmail = olUser.JobTitle

            If sEmail = specificTitle Then
                GALEmail = olUser.PrimarySmtpAddress
            End If
        End If
    Next i
End With

End Function

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM