如何为对象属性添加表格列?

huangapple go评论64阅读模式
英文:

How to add a table column for an object property?

问题

I understand that you're looking for the correct syntax to reference the Attachments object property for use in the oColumns.Add() method in Outlook VBA. You can use the following syntax:

oColumns.Add("http://schemas.microsoft.com/mapi/attachments")

This should allow you to add the Attachments property to your Outlook table successfully.

英文:

Working in Windows 11 Pro 64 and MS Office LTSC Pro Plus 2021.

I'm building a spreadsheet of properties of a selection of e-mails. I understand that the way to do this is to use an Outlook table generated by a command like oEmailFolder.GetTable(sFilter) and then add to the table columns for the properties that I want using a command like oOutlookTable.Columns.Add("property").

This question is a follow-up to my previous one on adding a table column for Sender and some other properties. I understand now that Sender and Attachments are objects, so adding them to the table is unsupported if they are referenced by name. Trying to do so yields "Run-time error '-2147024809 (80070057)': The property "Attachments" does not support this operation." But adding them is supposed to be "supported if property is referenced by its namespace". So I'm trying to do that.

Microsoft's documentation on Referencing Properties by Namespace has a section on Outlook Namespaces, which says that Outlook item-level properties can be referenced by:

urn:schemas-microsoft-com:office:outlook#name

So I tried to add Attachments using

oColumns.Add ("urn:schemas-microsoft-com:office:outlook#Attachments")

Doing that brought up the error:

Run-time error '-2147024809 (80070057)': The property "urn:schemas-microsoft-com:office:outlook#Attachments" is unknown.

That page also mentions another namespace that seemed promising, urn:schemas:mailheader, so I tried:

oColumns.Add ("urn:schemas:mailheader#Attachments")

From that, I got:

Run-time error '-2147024809 (80070057)': The property "urn:schemas:mailheader#Attachments" does not support this operation.

which is the same error I was getting when I tried to add it referencing it by name.

What is the correct syntax to reference this object property for use in the oColumns.Add() method?

答案1

得分: 2

这是相同的问题 - 你只能从表中检索标量值(字符串、整数、布尔值等)。收件人和附件被分别存储为子对象。你可以在Extended MAPI中搜索收件人或附件属性,但在Outlook对象模型中不能。发送者类似,尽管在Extended MAPI中实际上不存在 - 你有发送者姓名、电子邮件地址、条目ID等,但没有发送者对象。你可以随时检索发送者条目ID,并将其作为Namespace.GetAddressEntryFromID中的AddressEntry对象打开。

英文:

It is the same issue - you can only retrieve scalar values (strings, int, boolean, etc.) from a table. Recipients and Attachments are stored separately as subobjects. You can search on recipient or attachment properties in Extended MAPI, but not in Outlook Object Model. Sender is similar, even though it does not really exist in Extended MAPI - you have sender name, email address, entry id, etc., but not the sender object. You can always retrieve the sender entry id and open it as an AddressEntry object using Namespace.GetAddressEntryFromID.

huangapple
  • 本文由 发表于 2023年5月17日 13:14:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76268753.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定