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!
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With