我正在尝试为分发列表中具有特定名称的用户获取图片。在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
`
答案 0 :(得分:3)
只有在outlook.exe进程内运行时才能检索图片,即如果您的代码是在Outlook VBA或COM插件中:
来自https://msdn.microsoft.com/en-us/library/office/ff864210.aspx:
您只能从作为Outlook在进程中运行的代码调用GetPicture。无法跨进程边界封送StdPicture对象。如果您尝试从进程外代码调用GetPicture,则会发生异常