Using the visual database to access the subfolder in the inbox?

Dim olApp As Outlook.Application Dim objNS As Outlook.NameSpace Set olApp = Outlook.Application Set objNS = olApp.GetNamespace("MAPI") Set myOlItems = objNS.GetDefaultFolder(olFolderInbox).Items 

I used the code above to access the main Inbox, but how to access the folders in the Inbox and Send Mail using vba!

+4
source share
3 answers

It's very close:)

To get all mail items in a folder named "temp" in your inbox, try

 Dim olApp As Outlook.Application Dim objNS As Outlook.NameSpace Dim olFolder As Outlook.MAPIFolder Dim msg As Outlook.MailItem Set olApp = Outlook.Application Set objNS = olApp.GetNamespace("MAPI") Set olFolder = objNS.GetDefaultFolder(olFolderInbox) Set olFolder = olFolder.Folders("Temp") For Each msg In olFolder.Items Debug.Print msg.Subject Next 
+15
source

I found that in my mailbox there were some items that were not mail items causing the script to stop. This small change allowed the script to continue to work if something like a meeting request was found:

 Sub getmail() Dim olApp As Outlook.Application Dim objNS As Outlook.Namespace Dim olFolder As Outlook.MAPIFolder 'Dim msg As Outlook.MailItem Dim InboxItem As Object Set olApp = Outlook.Application Set objNS = olApp.GetNamespace("MAPI") Set olFolder = objNS.GetDefaultFolder(olFolderInbox) Set olFolder = olFolder.Folders("temp") For Each InboxItem In olFolder.Items Debug.Print InboxItem.Subject Debug.Print InboxItem.EntryID Next End Sub 

Thanks for your reply! helped me a lot!

(My apologies - I wanted to comment, but not enough rap.)

+3
source

And to continue further, continue to add the Set olFolder lines:

 Set olFolder = objNS.GetDefaultFolder(olFolderInbox) Set olFolder = olFolder.Folders("temp") Set olFolder = olFolder.Folders("temp2") Set olFolder = olFolder.Folders("temp3") 

Gets \ Inbox \ temp \ temp2 \ temp3 \

0
source

Source: https://habr.com/ru/post/1383808/


All Articles