Friday, 14 October 2016

Working with VBA and non-default Outlook Folders

This code sample uses a default Outlook folder:

Dim NS As Outlook.NameSpace
  Dim objOwner As Outlook.Recipient
   
  Set NS = Application.GetNamespace("MAPI")
  Set objOwner = NS.CreateRecipient("maryc")
    objOwner.Resolve
       
 If objOwner.Resolved Then
   'MsgBox objOwner.Name
 Set newCalFolder = NS.GetSharedDefaultFolder(objOwner, olFolderCalendar)

 End If

To add an item to a folder in a shared mailbox, use Items.add:
Set objAppt = newCalFolder.Items.Add(olAppointmentItem)

Default Folder Names

The following are the default folder names to use when referencing Outlook's default folders.
NameValueDescription
olFolderCalendar9Calendar folder
olFolderContacts10Contacts folder
olFolderDeletedItems3Deleted Items folder
olFolderDrafts16Drafts folder
olFolderInbox6Inbox folder
olFolderJournal11Journal folder
olFolderJunk23Junk E-Mail folder
olFolderNotes12Notes folder
olFolderOutbox4Outbox folder
olFolderSentMail5Sent Mail folder
olFolderSuggestedContacts30Suggested Contacts folder
olFolderTasks13Tasks folder
olFolderToDo28To Do folder
olPublicFoldersAllPublicFolders18All Public Folders folder in Exchange Public Folders store (Exchange only)
olFolderRssFeeds25RSS Feeds folder

0 comments:

Post a Comment