Discussion:
Handling Message Classes
(too old to reply)
McKilty
2009-10-06 22:32:55 UTC
Permalink
So I have a macro that is cyling through all of the items in an
Outlook folder and writes the details to a Word file. Everything
works great for regular mail messages (IPM.Note) but when it gets to
IPM.Schedule.Meeting.Request, it cannot read the TO or CC.

My first though is to use RequiredAttendees and OptionalAttendees, but
I get the error "Object doesn't support this property or method".

I think that over time, these won't be the only message classes I'll
have to deal with, so I'll probably need to write a SELECT CASE to
handle the various types, but I need to know the appropriate field
names.

My Code is below, but I've clipped a bunch of the Word references:
----------------------------------------------------------
'Export the selected folder into a Word file.

Dim sUser As String
Dim iRunCount As Integer
Dim bRunOnce As Boolean

Dim iItem As Integer
Dim myItem

Dim myOutlook As Outlook.Application
Dim myNameSpace As Outlook.NameSpace

Dim myWord As Word.Application
Dim myDoc As Word.Document
Dim sWordString As String
Dim sSaveLocation As String

sSaveLocation = "C:\"


Set myOutlook = Outlook.Application
Set myNameSpace = myOutlook.GetNamespace("MAPI")

Select Case UCase(myOutlook.ActiveExplorer.CurrentFolder.Name)
Case "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY",
"SATURDAY", "SUNDAY"
Case Else
If MsgBox("The intended use of this program is for the Daily Sent &
Received folders (Sun, Mon, Tue, etc.) only." & vbCrLf & vbCrLf & "Are
you sure you want to run this?", vbExclamation + vbYesNo, "Non-
Sanctioned Outlook Folder") = vbNo Then
Set myNameSpace = Nothing
Set myOutlook = Nothing

Exit Sub
End If
End Select


myWord.Selection.WholeStory
myWord.Selection.Delete Unit:=wdCharacter, Count:=1
myWord.Selection.Style = myDoc.Styles("Heading 2")
myWord.Selection.TypeText Text:="LEVEL 3"
myWord.Selection.TypeParagraph

If Outlook.ActiveExplorer.Selection.Count > 0 Then


For iItem = 1 To myOutlook.ActiveExplorer.CurrentFolder.Items.Count
Set myItem = myOutlook.ActiveExplorer.CurrentFolder.Items(iItem)

myWord.Selection.TypeText Text:="; Copied from: "
If myItem.MessageClass = "IPM.Schedule.Meeting.Request" Then
myWord.Selection.TypeText Text:=myItem.OptionalAttendees
Else
myWord.Selection.TypeText Text:=myItem.CC
End If

myWord.Selection.TypeText Text:="; Sent To: "
If myItem.MessageClass = "IPM.Schedule.Meeting.Request" Then
myWord.Selection.TypeText Text:=myItem.RequiredAttendees
Else
myWord.Selection.TypeText Text:=myItem.To
End If

Next iItem
End If
Next iRunCount

myWord.DisplayAlerts = wdAlertsNone
myDoc.ActiveWindow.ActivePane.View.Type = wdMasterView
myDoc.Save 'sWordFile
myDoc.Close

myWord.Quit

Set myDoc = Nothing
Set myWord = Nothing

Set myItem = Nothing

Set myEmail = Nothing
Set myNameSpace = Nothing
Set myOutlook = Nothing
---------------------------------------
McKilty
2009-10-06 22:49:27 UTC
Permalink
PS - It fails on either of these lines for a Meeting request. Word is
not the issue, it just doesn't recognize those properties.

myWord.Selection.TypeText Text:=myItem.OptionalAttendees

myWord.Selection.TypeText Text:=myItem.CC
Sue Mosher [MVP]
2009-10-07 01:11:11 UTC
Permalink
Check the value of the Class property of the item and then access only those
properties appropriate for the particular type of item. Use the object
browser to check what's available. For meeting requests, use the
GetAssociatedAppointment method to return an AppointmentItem.

You are correct that a Select Case ... End Select block will be helpful in
branching code for different item types.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
Post by McKilty
So I have a macro that is cyling through all of the items in an
Outlook folder and writes the details to a Word file. Everything
works great for regular mail messages (IPM.Note) but when it gets to
IPM.Schedule.Meeting.Request, it cannot read the TO or CC.
My first though is to use RequiredAttendees and OptionalAttendees, but
I get the error "Object doesn't support this property or method".
I think that over time, these won't be the only message classes I'll
have to deal with, so I'll probably need to write a SELECT CASE to
handle the various types, but I need to know the appropriate field
names.
----------------------------------------------------------
'Export the selected folder into a Word file.
Dim sUser As String
Dim iRunCount As Integer
Dim bRunOnce As Boolean
Dim iItem As Integer
Dim myItem
Dim myOutlook As Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myWord As Word.Application
Dim myDoc As Word.Document
Dim sWordString As String
Dim sSaveLocation As String
sSaveLocation = "C:\"
Set myOutlook = Outlook.Application
Set myNameSpace = myOutlook.GetNamespace("MAPI")
Select Case UCase(myOutlook.ActiveExplorer.CurrentFolder.Name)
Case "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY",
"SATURDAY", "SUNDAY"
Case Else
If MsgBox("The intended use of this program is for the Daily Sent &
Received folders (Sun, Mon, Tue, etc.) only." & vbCrLf & vbCrLf & "Are
you sure you want to run this?", vbExclamation + vbYesNo, "Non-
Sanctioned Outlook Folder") = vbNo Then
Set myNameSpace = Nothing
Set myOutlook = Nothing
Exit Sub
End If
End Select
myWord.Selection.WholeStory
myWord.Selection.Delete Unit:=wdCharacter, Count:=1
myWord.Selection.Style = myDoc.Styles("Heading 2")
myWord.Selection.TypeText Text:="LEVEL 3"
myWord.Selection.TypeParagraph
If Outlook.ActiveExplorer.Selection.Count > 0 Then
For iItem = 1 To myOutlook.ActiveExplorer.CurrentFolder.Items.Count
Set myItem = myOutlook.ActiveExplorer.CurrentFolder.Items(iItem)
myWord.Selection.TypeText Text:="; Copied from: "
If myItem.MessageClass = "IPM.Schedule.Meeting.Request" Then
myWord.Selection.TypeText Text:=myItem.OptionalAttendees
Else
myWord.Selection.TypeText Text:=myItem.CC
End If
myWord.Selection.TypeText Text:="; Sent To: "
If myItem.MessageClass = "IPM.Schedule.Meeting.Request" Then
myWord.Selection.TypeText Text:=myItem.RequiredAttendees
Else
myWord.Selection.TypeText Text:=myItem.To
End If
Next iItem
End If
Next iRunCount
myWord.DisplayAlerts = wdAlertsNone
myDoc.ActiveWindow.ActivePane.View.Type = wdMasterView
myDoc.Save 'sWordFile
myDoc.Close
myWord.Quit
Set myDoc = Nothing
Set myWord = Nothing
Set myItem = Nothing
Set myEmail = Nothing
Set myNameSpace = Nothing
Set myOutlook = Nothing
---------------------------------------
McKilty
2009-10-07 13:33:23 UTC
Permalink
Thanks, that worked for me.

Loading...