none
Outlook Meeting invite VBA Code Help RRS feed

  • Question

  • I am trying to create a Macro for meeting invitation that will look at the location, and if it finds certain text "Meet", it will then check the body of the invitation to see if one of two other phrases is present.  If it is, it sends the invite, if not, it provides a warning.  I created the code below with help.  But it is not working.

    Thanks

    Private WithEvents Items As Outlook.Items <-Is this the correct intro?  I wrote a similar macro for when sending an email and it started with Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
     
    Private Sub Application_Startup()
      Dim Ns As Outlook.NameSpace
      Set Ns = Application.GetNamespace("MAPI")
      Set Items = Ns.GetDefaultFolder(olFolderCalendar).Items
      Set MeetingText = AppointmentItem.Body < - should this be MeetingItem.Body?
      Set Meet = 0
    End Sub
     
    Private Sub Items_ItemAdd(ByVal Item As Object)
      On Error Resume Next
     
        If Item.Class = olAppointment Then
            If Item.Subject = "Meet" Then
                If InStr(1, Item.Body, "A meeting has been added.", vbTextCompare) > 0 Then Meet = 1
                If InStr(1, Item.Body, " IMPORTANT NOTICE: Please note that this service allows ", vbTextCompare) > 0 Then Meet = 1
            End If
       End If
                                                                                        
    If AmexMeet = 1 Then
            prompt = "This invite does not contain AmexMeet Link.  Do you want to proceed?"
            If MsgBox(prompt, vbYesNo + vbExclamation + vbMsgBoxSetForeground, "Check Address") = vbNo Then
                Cancel = True
            End If
    End If
     
    End Sub

    • Moved by Steve Fan Tuesday, July 25, 2017 2:03 AM
    Monday, July 24, 2017 4:05 PM

All replies

  • Hi Paul,

    Welcome to the Microsoft Office for IT Professionals Outlook forum. This forum is for general questions and feedback related to Microsoft Outlook. Since your questions is more related to VBA code, I'll move it to a more appropriate forum:

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=outlookdev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Regards,

    Steve Fan


    Please remember to mark the replies as answers if they helped.

    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, July 25, 2017 2:02 AM
  • Hello Paul,

    > Private WithEvents Items As Outlook.Items <-Is this the correct intro?  I wrote a similar macro for when sending an email and it started with Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    Yes, that is a correct declaration.

    > Set MeetingText = AppointmentItem.Body < - should this be MeetingItem.Body?

    You can't do so. You need to create a new appointment item or get an existing one. See

    > But it is not working.

    It is expected. The description doesn't correspond to the code listed above. For example, the following condition:

       If Item.Subject = "Meet" Then

    requires the the subject line can contain only the "Meet" word, nothing else. You can use the InStr function to determine whether a string (subject) contains any substring ("Meet").

    In general, I'd suggest running the code under the debugger and see what happens there going through each line of code. You may find the Getting Started with VBA in Outlook 2010 article helpful.  


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Tuesday, July 25, 2017 8:11 AM
  • Hi Paul - AZ,

    ->If Item.Class = olAppointment Then

    A meeting invitations class property is olMeetingRequest. You could check for item Class Enumeration and select correspondent value.

    I suggest you use ItemSend event to check Subject and body when you try to send a meeting invite.

    Here is the example.

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

    On Error Resume Next

    meet = 0

        If Item.Class = olMeetingRequest Then

            If InStr(Item.Subject, "Meeting") > 0 Then

                If InStr(1, Item.Body, "A meeting has been added.", vbTextCompare) > 0 Then meet = 1

                If InStr(1, Item.Body, " IMPORTANT NOTICE: Please note that this service allows ", vbTextCompare) > 0 Then meet = 1

            End If

       End If

    If meet = 0 Then

            prompt = "This invite does not contain AmexMeet Link.  Do you want to proceed?"

            If MsgBox(prompt, vbYesNo + vbExclamation + vbMsgBoxSetForeground, "Check Address") = vbNo Then

                Cancel = True

            End If

    End If

    End Sub

    Best Regards,

    Terry

    Wednesday, July 26, 2017 9:15 AM
  • Hi Paul-AZ,

    Has your original issue been resolved? If it has, I would suggest you mark the helpful reply or provide your solution and then mark it as answer to close this thread. 
    If not, please feel free to let us know your current issue.

    Best Regards,

    Terry

    Thursday, August 3, 2017 8:18 AM