View Single Post
 
Old 10-27-2018, 11:54 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You can loop through the stores and get their names and by adding them to a collection you can loop through the names e.g. as follows. However due to the many ways that Outlook can be configured, you may get duplicates. If the following shows duplicates with the same message counts then you can remove the duplicates by using. As you may not know what you are dealing with it may be better to simply leave the duplicates and process the folder twice.

Code:
oColl.Add oStore, oStore
'in place of
oColl.Add oStore
to add to the collection
Code:
Sub Macro1()
 Dim oStore As Store
Dim oFolder As Folder
Dim oColl As Collection
Dim i As Integer
    Set oColl = New Collection
    On Error Resume Next
    For Each oStore In Session.Stores
Debug.Print oStore
        oColl.Add oStore
    Next oStore
    On Error GoTo 0
    For i = 1 To oColl.Count
        Set oFolder = Session.Stores.Item(CStr(oColl(i))).GetDefaultFolder(olFolderInbox)
        'do something with ofolder
Debug.Print oFolder.Items.Count
    Next i
lbl_Exit:
    Set oFolder = Nothing
    Set oStore = Nothing
    Set oColl = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote