McKilty
2009-10-06 22:32:55 UTC
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
---------------------------------------
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
---------------------------------------