Code level: beginner    Code area: Basic Outlook
Title: Print appointment with attendee status
Description: A modification of Sue's solution in 24 Hours, 1999. This version does not use a template in order to keep deployment simpler. You need to add a reference to Word in your Outlook project. This generates an address book access warning.
Date: 15-Nov-2002  03:45
Code level: beginner
Code area: Basic Outlook
Posted by: John Retherford
Body:
Sub PrintAapptAttendee()
'  Gather data from an opened appointment and print to
'  Word.  This provides a way to print the attendee list with their
'  response, which Outlook will not do on its own.

' Set up Outlook
Dim objApp As Outlook.Application
Dim objItem As Object
Dim objSelection As Selection
Dim objAttendees As Outlook.Recipients
Dim objAttendeeReq As String
Dim objAttendeeOpt As String
Dim objOrganizer As String
Dim dtStart As Date
Dim dtEnd As Date
Dim strSubject As String
Dim strLocation As String
Dim strNotes As String
Dim strMeetStatus As String
Dim strUnderline As String ' Horizontal divider line

' Set up Word
Dim objWord As Word.Application
Dim objdoc As Word.Document
Dim wordRng As Word.Range
Dim wordPara As Word.Paragraph

On Error Resume Next

Set objApp = CreateObject("Outlook.Application")
Set objItem = objApp.ActiveInspector.CurrentItem
Set objSelection = objApp.ActiveExplorer.Selection
Set objAttendees = objItem.Recipients

Set objWord = GetObject(, "Word.application")
If objWord Is Nothing Then
 Set objWord = CreateObject("word.application")
End If

strUnderline = String(60, "_") ' use 60 underline characters

On Error GoTo EndClean:

' check for user problems with none or too many items open
Select Case objSelection.Count
    Case 0
      MsgBox "No appointment was opened.  Please opten the appointment to print."
      GoTo EndClean:
    Case Is > 1
      MsgBox "Too many items were selected.  Just select one!!!"
      GoTo EndClean:
End Select

' Is it an appointment
If objItem.Class <> 26 Then
  MsgBox "You First Need To open The Appointment to Print."
  GoTo EndClean:
End If

' Get the data
dtStart = objItem.Start
dtEnd = objItem.End
strSubject = objItem.Subject
strLocation = objItem.Location
strNotes = objItem.Body
objOrganizer = objItem.Organizer
objAttendeeReq = ""
objAttendeeOpt = ""

' Get The Attendee List
For x = 1 To objAttendees.Count
   strMeetStatus = ""
   Select Case objAttendees(x).MeetingResponseStatus
     Case 0
       strMeetStatus = "No Response (or Organizer)"
     Case 1
       strMeetStatus = "Organizer"
     Case 2
       strMeetStatus = "Tentative"
     Case 3
       strMeetStatus = "Accepted"
     Case 4
       strMeetStatus = "Declined"
   End Select
 
   If objAttendees(x).Type = olRequired Then
      objAttendeeReq = objAttendeeReq & objAttendees(x).Name & vbTab & strMeetStatus & vbCr
   Else
      objAttendeeOpt = objAttendeeOpt & objAttendees(x).Name & vbTab & strMeetStatus & vbCr
   End If
Next
 
' Word: Open a new doc and stuff it

objWord.Visible = True
Set objdoc = objWord.Documents.Add
Set objdoc = objWord.ActiveDocument
Set wordRng = objdoc.Range

With wordRng
    .Font.Bold = True
    .Font.Italic = False
    .Font.Size = 14
    .InsertAfter "Organizer: " & objOrganizer
    .InsertParagraphAfter
    .InsertAfter strUnderline
    .InsertParagraphAfter
    .InsertParagraphAfter
End With

Set wordPara = wordRng.Paragraphs(4)
With wordPara.Range
    .Font.Bold = False
    .Font.Italic = False
    .Font.Size = 12
    .InsertAfter "Subject:  " & strSubject
    .InsertParagraphAfter
    .InsertAfter "Location: " & strLocation
    .InsertParagraphAfter
    .InsertParagraphAfter
    .InsertAfter "Start:    " & dtStart
    .InsertParagraphAfter
    .InsertAfter "End:     " & dtEnd
    .InsertParagraphAfter
    .InsertParagraphAfter
    .InsertAfter "Required: "
    .InsertParagraphAfter
    .InsertAfter objAttendeeReq
    .InsertParagraphAfter
    .InsertAfter "Optional: "
    .InsertParagraphAfter
    .InsertAfter objAttendeeOpt
    .InsertParagraphAfter
    .InsertAfter strUnderline
    .InsertParagraphAfter
    .InsertAfter "NOTES"
    .InsertParagraphAfter
    .InsertAfter strNotes
End With
  
EndClean:
Set objApp = Nothing
Set objItem = Nothing
Set objSelection = Nothing
Set objAttendees = Nothing
Set objWord = Nothing
Set objdoc = Nothing
Set wordRng = Nothing
Set wordPara = Nothing

End Sub



All 29comments
Page [ 1 2 3 Next >>  
  15-Nov-2002  11:47   
Great sample, John, especially for people who want to know more about pushing text into Word. Another variation would be to insert a table and put the data into table cells, so that it all lines up very neatly.
  21-Jan-2003  02:50   
It prompts "Compile error: User-defined type not defined" message. It is stopped at

"Dim objWord As Word.Application" line.



Can you teach me how to run this macro? I am using Office XP.
  04-Mar-2003  21:32   
That error would usually indicate that you haven't added a reference to the Microsoft Word library to your project. If this is VBA, use Tools | References.
  28-Apr-2003  22:31   
I wrote a similar macro but copied the meeting info and all attendee info to the clipboard so the organizer can put it anywhere. Very useful when the person asking for the info isnt in the same physical area and you want to share via email
  07-May-2003  17:53   
Nice variation, Nancy! Would you might posting it here?
  23-Apr-2005  19:45   
I'm not getting an error message, (although I did get the access warning) but nothing prints. The debug highlights the very first line. Do I need to put something above "Sub PrintAapptAttendee()" ?
Thanks.
  23-Apr-2005  19:58   
I spoke too soon. For whatever reason, it didn't send to the printer, bit it did put the info into Word. I'm more than happy to just have to click on Print. Thanks so much for this code.
  22-Sep-2005  13:38   
From Microsoft OUTLOOK 2000 and Internet Explorer 2000, All print on the screen comes out in ITALICS
  22-Mar-2006  03:40   
This code was fantastic, saved me a TON of time on extracting responses to a meeting request (over 150 responses). I really needed the data in Excel, but it was simple enough to copy/paste. Great job and THANK YOU!
  25-Sep-2006  13:20   
How can we get the Item Organizer of an appointment from inside of a form?
Page [ 1 2 3 Next >>