Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using visual basic to access subfolder in 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 have used the code above to access the main outlook Inbox but how to access the folders in inbox and it's mail using vba!

like image 308
kinkajou Avatar asked Nov 30 '11 07:11

kinkajou


People also ask

How do I search a subfolder in inbox?

Get in to the email folder which you want to start searching within as well as its subfolders. 2. Click on the Instant Search box to activate the Search Tools, type the search condition in the box, and then click All Subfolders in the Scope group under Search tab.

Can I create subfolders in Inbox?

To help keep your emails organized, you can create subfolders or personal folders by using the New Folder tool. Click Folder > New Folder. Tip: You can also right-click any folder in the Folder Pane and click New Folder.

Why can't I see emails in subfolders in Outlook?

Now, click the View tab > Change View, and then click Apply Current View to Other Mail Folders on the View tab. In the Apply View dialog box, tick the checkbox for 'mailboxes and their subfolders' option. Also, tick the checkbox for 'Apply View to subfolders', and then click the OK button.


1 Answers

Thats very close :)

To get all the mail items in a folder called "temp" under the Inbox try this

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
like image 82
brettdj Avatar answered Sep 20 '22 13:09

brettdj