简体   繁体   English

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

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

I am using Outlook VBA codes to find a specific Email address by the unique job title in the Global Address List.我正在使用 Outlook VBA 代码通过全局地址列表中的唯一职位查找特定的电子邮件地址。 I have the code below, but I am not sure how I can rope the identifying of specific Email address in. I am using this as a Function so that I can call it in the Subroutine.我有下面的代码,但我不确定如何识别特定的电子邮件地址。我将其用作函数,以便可以在子例程中调用它。

I keep getting the error "Object variable or With block variable not set", but I don't know how I can edit in the code to remove the error.我一直收到错误“未设置对象变量或块变量”,但我不知道如何在代码中进行编辑以消除错误。 I get the error at this line: "Set olUser = olAddressEntry.GetExchangeUser".我在这一行收到错误:“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

Any help would be greatly appreciated!!任何帮助将不胜感激!!

I have figured how to get the Email Address with the job title as shown below:我已经想出了如何获得带有职位的电子邮件地址,如下所示:

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