Search code examples
vbaemailoutlook

How to add a table column for an object property?


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?


Solution

  • 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.