VBA Script that gets list of Outlook Notes using the Property Accessor

Option Explicit

' VBA Script that gets info on Outlook Notes using PropertyAccessor and various syntaxes
' (see other scripts at http://www.GregThatcher.com for other ways to get Note's properties)
' Property Tag Syntax looks like this http://schemas.microsoft.com/mapi/proptag/0x0005000b
' Property Tag Syntax is used for Outlook 'Properties' (defined by Outlook Object Model)
' Property ID Syntax looks like this http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8586001f
' Property ID Syntax is used for MAPI Named Properties (optional Outlook properties that can't be deleted) and UserProperties (properties you can add which are visible to the user)
' Named Property Syntax looks like this http://schemas.microsoft.com/mapi/string folloowed by a property name
' Named Property Syntax is used to create and view 'Named Properties" (properties you can create, but which are not visible to the user)
' Office document syntax looks like this: urn:schemas-microsoft-com:office:outlook#source-table-label
' Use Tools->Macro->Security to allow Macros to run, then restart Outlook
' Run Outlook, Press Alt+F11 to open VBA
' Programming by Greg Thatcher, http://www.GregThatcher.com
' THIS SCRIPT WILL ONLY RUN ON OUTLOOK 2007 OR LATER (it won't work on Outlook 2003 -- there is no propertyAccessor)
' To find the DASL definition of Outlook Properties, use the method described in Professional Outlook 2007 Programming (Programmer to Programmer)
' From the 'Views' menu, create a new view (but don't save it)
' Click on the 'Advanced' tab, and choose 'Filter'
' Choose a Field from the 'Field' dropdown, also choose a condition and value
' Click on the 'Sql tab'
' Check the 'Edit these Criteria' checkbox

Public Sub GetNotesInfoUsingPropertyAccessor()
    Dim Session As Outlook.NameSpace
    Dim Report As String
    Dim NotesFolder As Outlook.Folder

    Dim currentItem As Object
    Dim currentNote As Outlook.NoteItem

    Dim propertyAccessor As Outlook.propertyAccessor
    Dim stringArray() As String
    Dim index
    Dim currentString
    Set Session = Application.Session
    Set NotesFolder = Session.GetDefaultFolder(olFolderNotes)
    For Each currentItem In NotesFolder.Items
        If (currentItem.Class = olNote) Then
            Set currentNote = currentItem
            Set propertyAccessor = currentNote.propertyAccessor

            stringArray() = propertyAccessor.GetProperty("urn:schemas-microsoft-com:office:office#Keywords")
            For index = LBound(stringArray) To UBound(stringArray)
                Report = Report & "Categories (" & index & ") " & stringArray(index) & vbCrLf
            Next index

            Call AddToReportIfNotBlank(Report, "Color", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/id/{0006200E-0000-0000-C000-000000000046}/8b000003"))
            Call AddToReportIfNotBlank(Report, "Contacts", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8586001f"))
            ' Call AddToReportIfNotBlank(Report, "Content", propertyAccessor.GetProperty("urn:schemas:httpmail:textdescription"))
            Call AddToReportIfNotBlank(Report, "Created", propertyAccessor.GetProperty("urn:schemas:calendar:created"))
            Call AddToReportIfNotBlank(Report, "Do Not AutoArchive", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/850e000b"))
            ' Call AddToReportIfNotBlank(Report, "In Folder", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0e05001f"))
            Call AddToReportIfNotBlank(Report, "Messagee Class", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x001a001e"))
            Call AddToReportIfNotBlank(Report, "Modified", propertyAccessor.GetProperty("DAV:getlastmodified"))
            ' Call AddToReportIfNotBlank(Report, "Outlook Data File", propertyAccessor.GetProperty("urn:schemas-microsoft-com:office:outlook#source-table-label"))
            Call AddToReportIfNotBlank(Report, "Outlook Internal Version", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/85520003"))
            Call AddToReportIfNotBlank(Report, "Outlook Version", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8554001f"))
            Call AddToReportIfNotBlank(Report, "Subject", propertyAccessor.GetProperty("urn:schemas:httpmail:subject"))

            Report = Report & "----------------------------------------------------------------------------------" & vbCrLf & vbCrLf
        End If
    Call CreateReportAsEmail("List of Notes and Note properties using various Property Syntaxes", Report)
End Sub

Private Function AddToReportIfNotBlank(Report As String, FieldName As String, FieldValue)
    AddToReportIfNotBlank = ""
    If (IsNull(FieldValue) Or FieldValue <> "") Then
        AddToReportIfNotBlank = FieldName & " : " & FieldValue & vbCrLf
        Report = Report & AddToReportIfNotBlank
    End If
End Function

' VBA SubRoutine which displays a report inside an email
' Programming by Greg Thatcher, http://www.GregThatcher.com
Public Sub CreateReportAsEmail(Title As String, Report As String)
    On Error GoTo On_Error

    Dim Session As Outlook.NameSpace
    Dim mail As MailItem
    Dim MyAddress As AddressEntry
    Dim Inbox

    Set Session = Application.Session
    Set Inbox = Session.GetDefaultFolder(olFolderInbox)
    Set mail = Inbox.Items.Add("IPM.Mail")

    mail.Subject = Title
    mail.Body = Report


        Set Session = Nothing
        Exit Sub

    MsgBox "error=" & Err.Number & " " & Err.Description
    Resume Exiting

End Sub