![]()
The PostItem Object is one of the objects in the Outlook VBA object model hierarchy. These articles will show you how to programmatically manipulate them.
Follow the above links to learn more about the PostItem Object's methods, properties and events.
Create Post in default local folder
I assume the Inbox is the default local folder for Post Items.
Function CreatePost() As Outlook.PostItem Set CreatePost = Outlook.CreateItem(olPostItem) End Function
Create Posts in non-default local folder that holds Post items
Using Folder.Items.Add we can add Post Items to any folder that supports them.
Function CreatePostAltFolder(fldr As Outlook.MAPIFolder) As Outlook.PostItem
If fldr.DefaultItemType = olPostItem Then
Set CreatePostAltFolder = fldr.Items.Add(olPostItem)
End If
End Function
Create Post in shared default folder (Inbox)
Post Items may also be created in shared folders that you have access to from a particular mailbox. Simply pass in a Recipient object or the name of a recipient whose shared Inbox you want to access. This function will create the Post and return it to the calling procedure so it may be further manipulated in VBA.
If a Recipient object is passed to the function, we can access the Folder directly. If only a name is passed, a temporary Recipient object is created using the Outlook.NameSpace.CreateRecipient Method in order to reach the shared folder.
Function CreateSharedDefaultPost(recip As Variant) As Outlook.PostItem
Dim olNS As Outlook.NameSpace
Dim fldr As Outlook.MAPIFolder
Dim tempRecip As Outlook.Recipient
Select Case TypeName(recip)
Case "Recipient"
' Recipient object already created
Set fldr = olNS.GetSharedDefaultFolder(recip, olFolderInbox)
Case "String"
' create Recipient object
Set olNS = GetNS(GetOutlookApp)
Set tempRecip = olNS.CreateRecipient(recip)
Set fldr = olNS.GetSharedDefaultFolder(tempRecip, olFolderInbox)
End Select
Set CreateSharedDefaultAppointment = fldr.Items.Add(olPostItem)
End Function
Function GetNS(ByRef app As Outlook.Application) As Outlook.NameSpace
Set GetNS = app.GetNamespace("MAPI")
End Function
Function GetOutlookApp() As Outlook.Application
' returns reference to native Application object
Set GetOutlookApp = Outlook.Application
End Function