Following are several encapsulated functions for working with PostItem properties. Rather than incorporating them inline, I prefer to put method calls into their own function, passing in the appropriate object for the function to manipulate.
I feel this makes the code look cleaner (your mileage may vary).
I did not include sample code for each method. All you need to do is pass a PostItem Object to each function. See NoteItem Properties for sample code you can adapt, and The PostItem Object for various methods of creating PostItem Objects.
Return Actions collection
Function GetPostItemActions(post As Outlook.PostItem) As Outlook.Actions Set GetPostItemActions = post.Actions End Function
Return the Application Object
Function GetPostApplication(post As Outlook.PostItem) As Outlook.Application Set GetPostApplication = post.Application End Function
Return the PostItem Attachments Collection
Function GetPostAttachments(post As Outlook.PostItem) As Outlook.Attachments Set GetPostAttachments = post.Attachments End Function
AutoResolvedWinner Property
Function PostAutoResolvedWinner(post As Outlook.PostItem) As Boolean PostAutoResolvedWinner = ((post.Conflicts.Count > 0) And (post.AutoResolvedWinner)) End Function
Billing Information
The billing information string is returned by this function. By specifying text in the (optional) second parameter, you can also edit this property using this function.
Function PostBillingInfo(post As Outlook.PostItem, Optional billingInfo As String, _
Optional append As Boolean = False) As String
' set or get post billing information
If Len(billingInfo) > 0 Then
If append Then
' append value to existing
post.BillingInformation = post.BillingInformation & billingInfo
Else
' set value
post.BillingInformation = billingInfo
End If
End If
' return whether updated or replaced or just checking value
PostBillingInfo = post.BillingInformation
End Function
PostItem Body Property
Like the billing information property, you can return and edit the Post body with this function.
Function PostBody(post As Outlook.PostItem, Optional bodyText As String, _
Optional append As Boolean = False) As String
' set or get Post body text
If Len(bodyText) > 0 Then
' set body text
If append Then
' add to existing body text
post.body = post.body & bodyText
Else
' replace with new body text
post.body = bodyText
End If
End If
' return body, whether updated or replaced or just checking value
PostBody = post.body
End Function
Body Format
Specify the body format using this function.
Function PostBodyFormat(post As Outlook.PostItem, bodyFormat As OlBodyFormat) post.bodyFormat = bodyFormat End Function
PostItem Categories
Function GetPostCategories(post As Outlook.PostItem) As String GetPostCategories = post.Categories End Function
Class Property
Function GetPostClass(post As Outlook.PostItem) As OlObjectClass GetPostClass = post.Class End Function
Companies string
Function PostCompanies(post As Outlook.PostItem, Optional companyInfo As String, _
Optional append As Boolean = False) As String
' set or get Post companies string
If Len(companyInfo) > 0 Then
If append Then
' append value to existing
post.Companies = post.Companies & companyInfo
Else
' set value
post.Companies = companyInfo
End If
End If
' return whether updated or replaced or just checking value
PostCompanies = post.Companies
End Function
Check if a PostItem is in conflict with another PostItem
If the Conflicts.Count property is greater than zero, or the IsConflict property is True, a post is in conflict with another post.
Function IsPostInConflict(post As Outlook.PostItem) As Boolean IsPostInConflict = ((post.Conflicts.Count > 0) Or (post.IsConflict)) End Function
Post Conflicts collection
Function GetPostConflicts(post As Outlook.PostItem) As Outlook.Conflicts Set GetPostConflicts = post.Conflicts End Function
ConversationIndex Property
Function GetpostCI(post As Outlook.PostItem) As String GetpostCI = post.ConversationIndex End Function
ConversationTopic Property
Function GetpostCT(post As Outlook.PostItem) As String GetpostCT = post.ConversationTopic End Function
Creation Time
Return the post's creation time as a date to the calling procedure.
Function GetPostCreationTime(post As Outlook.PostItem) As Date GetPostCreationTime = post.CreationTime End Function
Download State
Function GetPostDownloadState(post As Outlook.PostItem) As OlDownloadState GetPostDownloadState = post.DownloadState End Function
Entry ID
Function GetPostEntryID(post As Outlook.PostItem) As String GetPostEntryID = post.EntryID End Function
ExpiryTime Property
This function returns the time a Post is set to expire.
Function PostExpiryTime(post As Outlook.PostItem, Optional expirationDate As Variant) As Date
' if expiration date is provided, change existing
If Not IsMissing(expirationDate) Then
If IsDate(expirationDate) Then
post.ExpiryTime = expirationDate
End If
End If
' return existing or updated expiry time
PostExpiryTime = post.ExpiryTime
End Function
FormDescription Collection
Function GetPostFormDescription(post As Outlook.PostItem) As Outlook.FormDescription Set GetPostFormDescription = post.FormDescription End Function
GetInspector Property
The Inspector Object for the PostItem is returned to the calling procedure.
Function GetPostInspector(post As Outlook.PostItem) As Outlook.Inspector Set GetPostInspector = post.GetInspector End Function
HTMLBody Property
Function PostHTMLBody(post As Outlook.PostItem, bodyText As Variant) As String
' change html body if text provided
If Not IsMissing(bodyText) Then
post.HTMLBody = bodyText
End If
' return existing or updated html body
PostHTMLBody = post.HTMLBody
End Function
Importance Property
Function PostImportance(post As Outlook.PostItem, Optional importance As Variant) As OlImportance
' change importance if it was provided
If Not IsMissing(importance) Then
post.importance = importance
End If
' return existing or updated importance
PostImportance = post.importance
End Function
InternetCodepage Property
Function GetPostICP(post As Outlook.PostItem) As Long GetPostICP = post.InternetCodepage End Function
ItemProperties collection
Function GetPostItemProperties(post As Outlook.PostItem) As Outlook.ItemProperties Set GetPostItemProperties = post.ItemProperties End Function
Return last modified time
Function GetPostLastModTime(post As Outlook.PostItem) As Date GetPostLastModTime = post.LastModificationTime End Function
Links collection
Function GetPostLinks(post As Outlook.PostItem) As Outlook.Links Set GetPostLinks = post.Links End Function
MarkForDownload property
Function PostMarkForDownload(post As Outlook.PostItem, _
Optional remoteStatus As OlRemoteStatus) As OlRemoteStatus
' set or get remote status
Select Case remoteStatus
' if remoteStatus is specified, set it for the current PostItem
Case olMarkedForCopy, olMarkedForDelete, olMarkedForDownload, _
olRemoteStatusNone, olUnMarked
post.MarkForDownload = remoteStatus
PostMarkForDownload = remoteStatus
Case Else
' just return current status
PostMarkForDownload = post.MarkForDownload
End Select
End Function
MessageClass property
Function AppointmentMessageClass(appt As Outlook.AppointmentItem, Optional msgClass As String) As String
' set or get Appointment message class
' what are the possible values?
If Len(msgClass) > 0 Then
appt.MessageClass = msgClass
AppointmentMessageClass = msgClass
Else
' return value
AppointmentMessageClass = appt.MessageClass
End If
End Function
Mileage Property
Function PostMileage(post As Outlook.PostItem, Optional mileageValue As String, _
Optional append As Boolean = False) As String
' set or get Post mileage
If Len(mileageValue) > 0 Then
If append Then
post.Mileage = post.Mileage & mileageValue
Else
post.Mileage = mileageValue
End If
End If
' return value, either appended, unchanged or changed
PostMileage = post.Mileage
End Function
NoAging Property
Function PostNoAging(post As Outlook.PostItem, Optional ageItem As Variant) As Boolean
' set or get Post aging
If Not IsMissing(ageItem) Then
post.NoAging = ageItem
End If
PostNoAging = post.NoAging
End Function
OutlookInternalVersion Property
Function PostInternalVersion(post As Outlook.PostItem) As Long PostInternalVersion = post.OutlookInternalVersion End Function
OutlookVersion Property
Function PostOutlookVersion(post As Outlook.PostItem) As String PostOutlookVersion = post.OutlookVersion End Function
Parent Property
Function GetPostParent(post As Outlook.PostItem) As Object Set GetPostParent = post.Parent End Function
ReceivedTime Property
Returns the time a post was received.
Function GetPostReceivedTime(post As Outlook.PostItem) As Date GetPostReceivedTime = post.ReceivedTime End Function
Saved Property
Function GetPostSaved(post As Outlook.PostItem) As Boolean GetPostSaved = post.Saved End Function
SenderEmailAddress Property
Function GetPostSenderEmail(post As Outlook.PostItem) As String GetPostSenderEmail = post.SenderEmailAddress End Function
SenderEmailType Property
Function GetPostSenderEmailType(post As Outlook.PostItem) As String GetPostSenderEmailType = post.SenderEmailType End Function
SenderName Property
Function GetPostSenderName(post As Outlook.PostItem) As String GetPostSenderName = post.SenderName End Function
Sensitivity Property
Function PostSensitivity(post As Outlook.PostItem, Optional sens As Variant) As OlSensitivity
' set sensitivity if one is provided
If Not IsMissing(sens) Then
post.Sensitivity = sens
End If
' return existing or updated sensitivity
PostSensitivity = post.Sensitivity
End Function
SentOn Property
Function GetPostSentDate(post As Outlook.PostItem) As Date GetPostSentDate = post.SentOn End Function
Session Property
Function GetPostSession(post As Outlook.PostItem) As Outlook.NameSpace Set GetPostSession = post.Session End Function
Size Property
Function GetPostSize(post As Outlook.PostItem) As Long GetPostSize = post.Size End Function
Subject Property
Function PostSubject(post As Outlook.PostItem) As String PostSubject = post.Subject End Function
UnRead Property
Function PostUnread(post As Outlook.PostItem, isUnread As Variant) As Boolean
' update existing if value provided
If Not IsMissing(isUnread) Then
If TypeName(isUnread) = "Boolean" Then
post.UnRead = isUnread
End If
End If
' return existing or updated unread status
PostUnread = post.unread
End Function
UserProperties collection
Function GetPostUserProperties(post As Outlook.PostItem) As Outlook.UserProperties Set GetPostUserProperties = post.UserProperties End Function
