VBA Script that gets list of Outlook Notes using the Outlook Object Model
Option Explicit
' VBA Script that gets list of Outlook Notes and their Properties using the Outlook Object Model
' 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
' See http://www.GregThatcher.com for other ways to get the properties of Notes
Public Sub GetListOfNotesUsingOutlookObjectModel()
On Error GoTo On_Error
Dim Session As Outlook.NameSpace
Dim Report As String
Dim NotesFolder As Outlook.Folder
Dim currentItem As Object
Dim currentNote As NoteItem
Set Session = Application.Session
Set NotesFolder = Session.GetDefaultFolder(olFolderNotes)
For Each currentItem In NotesFolder.Items
If (currentItem.Class = olNote) Then
Set currentNote = currentItem
Call AddToReportIfNotBlank(Report, "AutoResolvedWinner", currentNote.AutoResolvedWinner)
Call AddToReportIfNotBlank(Report, "Body", currentNote.Body)
Call AddToReportIfNotBlank(Report, "Categories", currentNote.Categories)
Call AddToReportIfNotBlank(Report, "Class", currentNote.Class)
' Call AddToReportIfNotBlank(Report, "Conflicts", currentNote.Conflicts)
Call AddToReportIfNotBlank(Report, "CreationTime", currentNote.CreationTime)
Call AddToReportIfNotBlank(Report, "DownloadState", currentNote.DownloadState)
Call AddToReportIfNotBlank(Report, "EntryID", currentNote.EntryID)
Call AddToReportIfNotBlank(Report, "Height", currentNote.Height)
Call AddToReportIfNotBlank(Report, "IsConflict", currentNote.IsConflict)
' Report = Report & AddToReportIfNotBlank("ItemProperties", currentNote.ItemProperties)
Call AddToReportIfNotBlank(Report, "LastModificationTime", currentNote.LastModificationTime)
Call AddToReportIfNotBlank(Report, "Left", currentNote.Left)
' Call AddToReportIfNotBlank(Report, "Links", currentNote.Links)
Call AddToReportIfNotBlank(Report, "MarkForDownload", currentNote.MarkForDownload)
Call AddToReportIfNotBlank(Report, "MessageClass", currentNote.MessageClass)
Call AddToReportIfNotBlank(Report, "Saved", currentNote.Saved)
Call AddToReportIfNotBlank(Report, "Size", currentNote.Size)
Call AddToReportIfNotBlank(Report, "Subject", currentNote.Subject)
Call AddToReportIfNotBlank(Report, "Top", currentNote.Top)
Call AddToReportIfNotBlank(Report, "Width", currentNote.Width)
Report = Report & vbCrLf & vbCrLf
End If
Next
Call CreateReportAsEmail("List of Notes", Report)
Exiting:
Exit Sub
On_Error:
MsgBox "error=" & Err.Number & " " & Err.Description
Resume Exiting
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 As Outlook.Folder
Set Session = Application.Session
Set Inbox = Session.GetDefaultFolder(olFolderInbox)
Set mail = Inbox.Items.Add("IPM.Mail")
Set MyAddress = Session.CurrentUser.AddressEntry
mail.Recipients.Add (MyAddress.Address)
mail.Recipients.ResolveAll
mail.Subject = Title
mail.Body = Report
mail.Save
mail.Display
Exiting:
Set Session = Nothing
Exit Sub
On_Error:
MsgBox "error=" & Err.Number & " " & Err.Description
Resume Exiting
End Sub
|