Creating Mailbox Top Level Folder with VBA



I am trying to work out how to create a folder in Outlook that is on the same
level as the Inbox. The code I am working with is:

Dim onMAPI As NameSpace
Dim ofInboxFolder As MAPIFolder
Dim ofNewFolder As MAPIFolder

Set onMAPI = Application.GetNamespace("MAPI")
Set ofInboxFolder = onMAPI.GetDefaultFolder(olFolderInbox)

On Error Resume Next
If ofInboxFolder.Folders("New Folder") Is Nothing Then
ofInboxFolder.Folders.Add "New Folder", olFolderInbox
End If

Set ofInboxFolder = Nothing
Set ofNewFolder = Nothing
Set onMAPI = Nothing

How to I make this: Set ofInboxFolder = onMAPI.GetDefaultFolder(olFolderInbox)
be the "Mailbox - Username" Folder?

On the same point, how do I then reference this new folder to capture when a
new message is dropped/created in it?

Thanks in advance.



Sue Mosher [MVP-Outlook]

The Inbox has a Parent, and Folders.Add returns the new folder:

Set newFolder = ofInboxFolder.Parent.Folders.Add("New Folder", olFolderInbox)

Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question