none
Outlook VBA code error? (Trying to create a 'copy meeting' function!) RRS feed

  • Question

  • Hello! I found VBA code online that copies appointments, verified that it worked, and I've been trying to adjust it for Meetings, as in, includes recipients and just convert it to an appointment. This is my first time trying to create a module.

    I seem to be running into issues because of the Object differences between appointments and meetings... the original code is at (new account, can't place link, so space after www.  - http://www. howto-outlook.com/howto/openapptcopy.htm#macrocode ) and my attempt to adjust is below. When I run it the debug hits "Set olMeetingCopy = Outlook.CreateItem(olMeeting)" and says the item is empty - it used to be (olAppointmentItem), but (olMeetingItem) doesn't appear to function in the same way, and I'm not sure what the correct replacement is?

    Any help whatsoever greatly appreciated - even if just to tell me that Meetings don't work the same way as appointments and I can't do it! I'm so sorry if my terminology is off; serious newb here. 

    Thank you so much! - Emily

    Sub OpenMeetingCopy()

    '=================================================================
    'Description: Outlook macro to create a new Meeting with
    '             specific details of the currently selected
    '             Meeting and show it in a new window.
    '
    ' author : Robert Sparnaaij
    ' version: 1.0
    ' website: http://www.howto-outlook.com/howto/openapptcopy.htm
    '=================================================================

        Dim objOL As Outlook.Application
        Dim objSelection As Outlook.Selection
        Dim objItem As Object
        Set objOL = Outlook.Application
        
        'Get the selected item
        Select Case TypeName(objOL.ActiveWindow)
            Case "Explorer"
                Set objSelection = objOL.ActiveExplorer.Selection
                If objSelection.count > 0 Then
                    Set objItem = objSelection.Item(1)
                Else
                    Result = MsgBox("No item selected. " & _
                                "Please make a selection first.", _
                                vbCritical, "OpenMeetingCopy")
                    Exit Sub
                End If
            
            Case "Inspector"
                Set objItem = objOL.ActiveInspector.CurrentItem
                
            Case Else
                Result = MsgBox("Unsupported Window type." & _
                            vbNewLine & "Please make a selection" & _
                            "in the Calendar or open an item first.", _
                            vbCritical, "OpenMeetingCopy")
                Exit Sub
        End Select

        Dim olMeeting As Outlook.MeetingItem
        Dim olMeetingCopy As Outlook.MeetingItem
        Set olMeetingCopy = Outlook.CreateItem(olMeeting)
            
        'Copy the desired details to a new Meeting item
        If objItem.Class = olMeeting Then
            Set olMeeting = objItem
            
            With olMeetingCopy
                .Subject = olMeeting.Subject
                .Location = olMeeting.Location
                .Body = olMeeting.Body
                .Categories = olMeeting.Categories
                .AllDayEvent = olMeeting.AllDayEvent
            End With
            
            'Display the copy
            olMeetingCopy.Display
        
        'Selected item isn't an Meeting item
        Else
            Result = MsgBox("No Meeting item selected. " & _
                        "Please make a selection first.", _
                        vbCritical, "OpenMeetingCopy")
            Exit Sub
        End If
        
        'Clean up
        Set objOL = Nothing
        Set objItem = Nothing
        Set olMeeting = Nothing
        Set olMeetingCopy = Nothing
        
    End Sub

    Monday, July 20, 2015 4:19 PM

Answers

  • Hello,

    To create a meeting you need to set the MeetingStatus property of the AppointmentItem class to the olMeeting value:

     
    Set myItem = myOlApp.CreateItem(olAppointmentItem)  
    myItem.MeetingStatus = olMeeting  
    myItem.Subject = "Strategy Meeting"  
    myItem.Location = "Conference Room B" 
    myItem.Start = #7/24/2015 1:30:00 PM#
    myItem.Duration = 90  
    Set myRequiredAttendee = myItem.Recipients.Add("Eugene Astafiev")  
    myRequiredAttendee.Type = olRequired  
    Set myOptionalAttendee = myItem.Recipients.Add("Kevin Kennedy")  
    myOptionalAttendee.Type = olOptional  
    Set myResourceAttendee = myItem.Recipients.Add("Conference Room B")  
    myResourceAttendee.Type = olResource  
    myItem.Send

    To create a copy you can use the Copy method of the AppointmentItem class.


    Monday, July 20, 2015 4:25 PM

All replies

  • Hello,

    To create a meeting you need to set the MeetingStatus property of the AppointmentItem class to the olMeeting value:

     
    Set myItem = myOlApp.CreateItem(olAppointmentItem)  
    myItem.MeetingStatus = olMeeting  
    myItem.Subject = "Strategy Meeting"  
    myItem.Location = "Conference Room B" 
    myItem.Start = #7/24/2015 1:30:00 PM#
    myItem.Duration = 90  
    Set myRequiredAttendee = myItem.Recipients.Add("Eugene Astafiev")  
    myRequiredAttendee.Type = olRequired  
    Set myOptionalAttendee = myItem.Recipients.Add("Kevin Kennedy")  
    myOptionalAttendee.Type = olOptional  
    Set myResourceAttendee = myItem.Recipients.Add("Conference Room B")  
    myResourceAttendee.Type = olResource  
    myItem.Send

    To create a copy you can use the Copy method of the AppointmentItem class.


    Monday, July 20, 2015 4:25 PM
  • Thank you, Eugene! That makes sense (so a Meeting is a form of Appointments in VBA?) - where in the code would you recommend that I insert the MeetingStatus Property? 
    Monday, July 20, 2015 4:42 PM
  • Appointment *is* a meeting. You are attempting to create an item of type olMeeting. You cannot do that - MeetignItem is created when you send a meeting request or update by calling AppointmentItem.Send. Create an item of type olAppointmentItem. 

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, July 20, 2015 5:05 PM
  • Got it! Thank you, Dmitry. I will work from there. I fundamentally didn't understand the relationship between Appointment and meeting. 
    Monday, July 20, 2015 5:44 PM
  • Appointment item can be a meeting if you set the MeetingStatus property as the sample code demonstrates above.
    Monday, July 20, 2015 6:09 PM