我试图获取通讯组列表中具有特定名称的用户的图片。在OUTLOOK VBA中,代码可以工作。在EXCEL VBA中,代码在getpicture
调用时失败。从通用VBS运行代码,代码执行getpicture
调用,但返回null。getexchangeuser
调用在所有三种情况下都可以工作。我需要帮助获得图片,然后保存它取决于如果格式是很难保存从VBA。
Sub test()
HeroName = "test"
HLastName = Split(HeroName, " ")(1)
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olAL As Outlook.AddressList
Dim olEntry As Outlook.AddressEntry
Dim olMember As Outlook.AddressEntry
Dim lMemberCount As Long
Dim objMail As Outlook.MailItem
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olAL = olNS.AddressLists("Global Address List")
Set objMail = olApp.CreateItem(olMailItem)
' enter the list name
Set olEntry = olAL.AddressEntries("##distribution list##")
' get count of dist list members
lMemberCount = olEntry.Members.Count
' loop through dist list and extract members
Dim i As Long
For i = 1 To lMemberCount
Set olMember = olEntry.Members.Item(i)
' NONE OF THIS CODE IS NECESSARY UNLESS IN THE FUTURE SVIL HAS MEMBERS WHO SHARE THE SAME LAST NAME
'AS A RESULT THE CODE IS NOT BEING UTILIZED
strName = olMember.Name
LastName = Split(strName, ",")(0)
'MsgBox (LastName)
If (InStr(HLastName, LastName)) Then
MsgBox (LastName)
'ActiveWorkbook.Sheets("Sheet2").Pictures.Insert
Dim returnValue As StdPicture
'MsgBox (olMember.GetExchangeUser)
'MsgBox (olMember.GetExchangeUser.GetPicture)
End If
Next i
End Sub
'
1条答案
按热度按时间xlpyo6sf1#
图片只能在outlook.exe进程中运行时检索,即如果您的代码在Outlook VBA或COM加载项中:
从https://msdn.microsoft.com/en-us/library/office/ff864210.aspx开始:
只能从作为Outlook在进程内运行的代码调用GetPicture,StdPicture对象不能跨进程边界封送,如果尝试从进程外代码调用GetPicture会出现异常
2023年3月更新
ExchangeUser.GetPicture
不再工作。Microsoft不再将图片存储在PR_EMS_AB_THUMBNAIL_PHOTO
二进制属性中的GAL中(至少对于M365托管的邮箱)。首先,它只能在在线(但不缓存)GAL enty中使用,现在完全从GAL中消失。Outlook本身使用Graph来检索图片,现在看来这是唯一的方法。