Analogous Outlook code to read info into an array (or collection or whatever)

Post number 2 has been selected as the best answer.

Status
Not open for further replies.

Dr. Demento

Member
OS Version(s)
  1. Windows
Outlook version
Outlook 365 64 bit
Email Account
Office 365 Exchange
Operating system::    Win 11
Outlook version:     365
Email type or host:    365 Exchange

In Excel, you can copy a range into an array (Range.value = array), thereby removing the time/memory needed to constantly access the spreadsheet. Is there an analogous method to read email data (send, subject, to, body, attachments, etc) into a similar digital construct en masse as an Excel array so that each individual email doesn't need to be accessed.

It's probably important to note that most of these emails are digitally encrypted; if this isn't possible for encrypted email, is there a method for unencrypted emails??

Thanks much.
 
You can read the values into an array - but would need to touch each message to get the field(s) you need. Basically, get the values from each message field into a string - strSubject = olmail.subject & "," & strSubject. Then convert the finished string in to an array.
 
One possible approach would be to construct a Search Folder that includes the Items you're interested in. But Search Folders come with a few limitations on where they can pull Items from, so this may not work for you.

Once you have the Search Folder built, you can access the Items in the folder using the standard Outlook Items collection syntax. You can walk it with "For Each" or get an individual Item with "Items(n)".

e.g. With a Search Folder as the Active Explorer:

Code:
    Dim oFolder As Outlook.Folder
    Set oFolder = ActiveExplorer.CurrentFolder
    
    Dim Item As Object
    For Each Item In oFolder.Items
        Debug.Print Item.Subject
    Next Item
    
    Dim Items As Outlook.Items
    Set Items = oFolder.Items
    Dim Inx As Long
    For Inx = 1 To Items.Count
        Debug.Print Items(Inx).Subject
    Next Inx
 
If your selection criteria are dynamic then you could use a DASL Filter and Application.AdvancedSearch instead of a Search Folder to get a Results collection. (I find that DASL Filters can get pretty complex really quick and the syntax is abominable). A similar approach to get a subset of Items from a Folder (also using a DASL Filter) is to build a Table Object. The advantage here is that the Table Object looks to you like a two dimension array of Rows (Items) and Columns (Fields from the Item).
 
To build some DASL queries you can use the Outlook View Filter dialog on any View to build your query using the Filter tabs and then copy the DASL from the "SQL" tab. See these Slipstick articles:

Create views using SQL/DAVX filters
Using Query Builder

e.g. Using Query Builder
1733581287180.png
1733581304210.png


e.g. Using the Messages, More Choices, and Advanced tabs
1733581537193.png
1733581558721.png


1733581612545.png
1733581632908.png


1733581504485.png
 
And then there is Items.Restrict to dynamically filter a Folder's Items collection. (Sorry for all the separate post. Microsoft has so many ways to skin this cat, that every time I finish one post I remember another one). There is an overview of the different ways you can filter a single folder here. But for queries that span multiple folders you have to look at other methods.
 
On rereading your original post (and looking up how an Excel Range works) I think you want a Table.

"You can regard each row of a Table as an item in the folder, each column as a property of the item, and the Table as an in-memory lightweight rowset that allows fast enumeration and filtering of items in the folder. If you don't specify any filter, you'll obtain all the items in the folder."
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
G Data Left Behind when Migrating To Outlook from Thunderbird - Insights on the Issue Using Outlook 0
C Can't Use Custom Contact form in Outlook Classic since early January 2026 Outlook VBA and Custom Forms 7
e_a_g_l_e_p_i Need help updating email in Outlook 2021 Using Outlook 10
V Outlook spam filter misbehaving Using Outlook 6
L what are the downsides of running both classic and new outlook on same win 11 pc? Using Outlook 2
P Preventing permanent deletions in Outlook on the Web Using Outlook 0
L any trick to embedding images in new outlook and outlook on the web contacts? Using Outlook 4
L new outlook contacts searching Using Outlook 5
R Outlook 2010 Outlook 2010 migration question Using Outlook 2
W New Outlook PEOPLE blank Using Outlook 6
C New Outlook issues with Gmail, particularly labels/folders Using Outlook 3
E What is the next workaround for macro in New Outlook 1.2025.1111.100 Outlook VBA and Custom Forms 3
E Need to digitally sign macro but VBA\Outlook crash Outlook VBA and Custom Forms 4
P Outlook 2003 no longer opens "without" Folder List Showing in Navigation Pane Using Outlook 2
Hornblower409 Outlook 2010 - Never ending update Using Outlook 0
V Outlook created new profile? Using Outlook 1
J Outlook inbox question Using Outlook 4
T How to Add AT&T Contacts to Outlook 365 Using Outlook 5
F Outlook 2021 outlook on iPhone Using Outlook 1
F Outlook 2021 Outlook on iPhone asks for password Using Outlook 0
P ics calendar entries suddenly open up new Outlook Using Outlook 3
P Outlook "forgets" password until system rebooted Using Outlook 2
N Why does Outlook keeping adding to the email address I have in my notes portion of a contact? Using Outlook 2
M Anyone integrated AI website builders with Outlook for automated client communications? Using Outlook 1
V Gmail in Outlook Using Outlook 2
T Where has the Copilot icon gone in my Outlook desktop client? Using Outlook 7
P New way by Microsoft to get people to use the new Outlook Using Outlook 4
C How to keep emails in account in Outlook after closing the IMAP account Using Outlook 1
cymumtaz IMAP calendars in New Outlook Using Outlook 5
T Constantly Have To Log In To Outlook On The Web Using Outlook.com accounts in Outlook 2
T Cannot Find Outlook Noted On Android Using Outlook 4
O Outlook 2024 not showing that messages are replied to or forwarded Using Outlook 3
C Outlook 365 send/receive takes FOREVER - as in 40 minutes Using Outlook 7
I Outlook 2024 LTSC syncing with iCloud calendar - can only make appt. in iCloud Using Outlook 2
Kika Melo Outlook ribbon customisations do not 'stick' Using Outlook 12
J IMAP Folders Confusion in Windows Classic Outlook Using Outlook 1
A Missing Sent Emails in New Outlook Using Outlook 18
S Missing categories in Outlook calendar Using Outlook 10
P Windows 11 tries to open New Outlook when the user clicks on the mail icon on a news article Using Outlook 2
C I don't understand Outlook or Microsoft, anymore Using Outlook 12
P My Feedback to Microsoft and their response; also New Outlook roadmap Using Outlook 0
A New Outlook - Cannot drag IMAP emails to Task List in MyDay Using Outlook 1
L Android Outlook Doesn't Update PC Notification Changes Using Outlook 0
A How to open Excel file saved in Outlook folder? Outlook VBA and Custom Forms 4
D.Moore Outlook desktop client suggested searches question Using Outlook 22
Y Outlook 2016 (64-bit) Copy Local Cal. Events to Another Cal. with Modified Reminder time Using Outlook 2
T Outlook 2019 While connecting an IMAP account in "classic" Outlook 2024 I caused a massive duplication of emails on the server (death loop) Using Outlook 5
D Cannot logon to Outlook.com, or outlook on Mac, outlook not updating on ipad, iphone Using Outlook 1
J unable to get my new install of Outlook to display mailboxes in the single-line format. Using Outlook 1
D Legacy Microsoft Outlook for Mac Support will end in Oct 2025 Using Outlook 8

Similar threads

Back
Top