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?