0

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

When I attempt to build a table of properties of selected e-mails, I'm not able to add a table column for Sender or six other e-mail properties.

Here is my code:

Public Sub TestMail()

' Get a Table object of e-mails from folder "Deleted Items" with subject "Test".

' Adapted from example code at "https://learn.microsoft.com/en-us/office/vba/api/outlook.folder.gettable"

' Result:
'   If bAddSender is true:
'       Error on: oTable.Columns.Add ("Sender")
'       Run-time error '-2147024809 (80070057)': The property "Sender" does not support this operation .
'       Same error for properties SendUsingAccount, Recipients, Attachments, Saved, Sent, and Session.
'   Otherwise:
'       Immediate window: "2009 03 25 07:03:00, test"

Dim sFolder As String, sFilter As String, _
    oMSOutlook As NameSpace, oFolder As Outlook.Folder, oTable As Outlook.Table, oRow As Outlook.Row, _
    bAddSender As Boolean

sFilter = "[Subject] = ""Test"""
bAddSender = False

Set oMSOutlook = Application.GetNamespace("MAPI")
Set oFolder = oMSOutlook.GetDefaultFolder(olFolderDeletedItems)

Set oTable = oFolder.GetTable(sFilter)
oTable.Columns.Add ("ReceivedTime")
If bAddSender Then
    oTable.Columns.Add ("Sender")
  End If

Set oRow = oTable.GetNextRow
Debug.Print (oRow("ReceivedTime") & ", " & oRow("Subject"))

End Sub     ' TestMail()

The code to add a table column ReceivedTime works, but, as indicated in the comments, trying to add a column for property Sender (bAddSender true) or several other properties yields the error:

Run-time error '-2147024809 (80070057)': The property "Sender" does not support this operation .

Otherwise, the code works. If I don't try to add a column for "Sender", then I get a correct timestamp and subject line.

Edit: The list of seven columns I'm trying to add:

Sender, SendUsingAccount, Recipients, Attachments, Saved, Sent, and Session

comes from Microsoft's list of MailItem properties. A comment below from Tim Williams says he was able to add a column for From. That's interesting because it's not in the list. I tried it now and it also works for me. From that, we learn that there's an undocumented property, From. But the question remains:

Why am I not able to add a table column for Sender or the other six properties?

Ken White
  • 123,280
  • 14
  • 225
  • 444
NewSites
  • 1,402
  • 2
  • 11
  • 26
  • `oTable.Columns.Add "From"` works for me... – Tim Williams May 15 '23 at 18:43
  • @TimWilliams - Yeah, me too. See my edit based on your comment. – NewSites May 15 '23 at 19:02
  • "senderemailaddress" also works for me. – Tim Williams May 15 '23 at 20:35
  • Related thread: https://stackoverflow.com/questions/57500026/fastest-way-to-pull-gettable-recipient-email-addresses-in-outlook-vba – Tim Williams May 15 '23 at 20:44
  • 1
    [Columns.Add method (Outlook)](https://learn.microsoft.com/en-us/office/vba/api/outlook.columns.add) has a link to [Unsupported Properties in a Table Object or Table Filter](https://learn.microsoft.com/en-us/office/vba/outlook/how-to/search-and-filter/unsupported-properties-in-a-table-object-or-table-filter) – niton May 15 '23 at 21:13
  • @niton - That explains the problem with Recipients, Attachments, Saved, and Sent, so thank you for that. But it does not help with Sender, SendUsingAccount, or Session. Do you know what the problem is with them? – NewSites May 15 '23 at 21:50
  • 1
    As indicated in the Unsupported Properties link and by Dmitry Streblechenko, "Properties returning an object" not supported. [MailItem.Sender property (Outlook)](https://learn.microsoft.com/en-us/office/vba/api/outlook.mailitem.sender) "Returns or sets an AddressEntry object", [MailItem.SendUsingAccount property (Outlook)](https://learn.microsoft.com/en-us/office/vba/api/outlook.mailitem.sendusingaccount) "Returns or sets an Account object" and [Account.Session property (Outlook)](https://learn.microsoft.com/en-us/office/vba/api/outlook.account.session) "Returns the NameSpace object". – niton May 15 '23 at 22:45
  • Alright, it looks like Dmitry's answer and niton's two comments add up to a complete and helpful answer. So thank you. I'm upvoting them all, but for an accepted answer, it would be good if someone would combine it all into one answer. It would also be good to talk about what seems to be a workaround on the Unsupported Properties page, to reference it "by its namespace," whatever that means. There's some code at the bottom of that page that's about referencing by namespace, but it says it's for computed properties, not object properties, so I wonder if it's applicable to the latter. – NewSites May 15 '23 at 23:31

2 Answers2

2

Sender is an object (AddressEntry) property, you cannot retrieve it from a table. Specify SenderName and/or SenderEmailAddress property.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
0

To summarize and expand on the answer and comments, those properties cannot be added to a table because:

Objects and computed properties are not supported in Outlook tables, as documented in Unsupported Properties in a Table Object or Table Filter.

NewSites
  • 1,402
  • 2
  • 11
  • 26