plitvicer
plitvicer

Reputation: 11

VBA: not all Outlook Emails show up

I wrote a small piece of code, that checks an additional inbox (besides my main-adress in Outlook) for E-Mails.

The problem shows up, when using the code on a pc, where only the additional inbox is added to outlook (as the main inbox). Obviously, the code can't retrieve all Emails, only the older ones. That's awkward, because the path to the subfolders and even the emails seem to be found, but not the newer ones. I can see them in Outlook with no problem.

Does anyone have an idea, why this is happening? As I told, the same code works with no problem on a PC with an Outlook-Installation, with another main-inbox and the inbox that needs to be checked as additional one.

That's the code I use to access Outlook and the Emails:

Dim objFolder As Outlook.Folder
Dim objOL As Outlook.Application
Set objOL = CreateObject("Outlook.Application")    
Set objFolder = objOL.GetNamespace("MAPI").Folders.Item("[email protected]").Folders.Item("Posteingang").Folders.Item("Subfolder-Name").Folders.Item("Subfolder-Name-2")
With objFolder.Items(1)
...

Upvotes: 1

Views: 3399

Answers (3)

Alister Fong
Alister Fong

Reputation: 11

I have found that changing the cache mode setting in Outlook helps with this problem of emails being in Microsoft Exchange not being accessed thru Excel VBA, especially Step (3) below.

https://support.microsoft.com/en-us/office/turn-on-cached-exchange-mode-7885af08-9a60-4ec3-850a-e221c1ed0c1c

  1. Click File > Account Settings > Account Settings.
  2. Click the Exchange or Microsoft 365, and then click Change.
  3. Under Offline Settings, check Use Cached Exchange Mode. (If you're a Microsoft 365 subscriber with semi-annual updates, under Offline Settings, check Use Cached Exchange Mode to download email to an Outlook data file.

Upvotes: 1

user10969436
user10969436

Reputation: 11

I had this same issue: in my case the emails were in microsoft exchange but were not downloaded to the local outlook.

If you can refresh the outlook it should resolve the problem

Upvotes: 1

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66215

Why are you always retrieving the first item in the Items collection? Would you not want to loop through the items?

set objItems = objFolder.Items
objItems.Sort "[ReceivedTime]"
'now objItems is sorted

Upvotes: 0

Related Questions