Search code examples
vbaoutlookms-wordcopy-paste

Outlook VBA: Using Word Inspector to create a Follow Up Meeting Invite


I am creating a VBA Macro in Outlook that will copy an existing meeting invite and create a follow up meeting invite. It should be fairly easy since I have all the parts to this puzzle.

My problem is with the body of the invite; all formatting and pictures are lost. For this reason, I need to use the Word Inspector object to preserve any special formatting and images. I figured out the code using Word and recording a macro.

So I have figured out the code for copying text using the Word Inspector, but I am not sure on how to paste it in another invite.

Sub copyPaste()
    Dim objOL As Outlook.Application
    Dim objNS As Outlook.NameSpace
    On Error Resume Next
    Set objOL = Application
    If objOL.ActiveInspector.EditorType = olEditorWord Then
        Set objDoc = objOL.ActiveInspector.WordEditor
        Set objNS = objOL.Session
        Set objSel = objDoc.Windows(1).Selection
        objSel.WholeStory
        objSel.Copy
        objSel.PasteAndFormat (wdFormatOriginalFormatting)
    End If
    Set objOL = Nothing
    Set objNS = Nothing
End Sub

Please see my current Outlook code:

Sub scheduleFollowUpMeeting()
  'Declarations
  Dim obj As Object
  Dim Sel As Outlook.Selection
  'Selecting the Email
  If TypeOf Application.ActiveWindow Is Outlook.Inspector Then
    Set obj = Application.ActiveInspector.currentItem
  Else
    Set Sel = Application.ActiveExplorer.Selection
    If Sel.Count Then
      Set obj = Sel(1)
    End If
  End If

  If Not obj Is Nothing Then
    MsgBox "The original meeting has been copied." & vbCrLf & "Please kindly update any new details like date/time.", , "Follow Up Meeting - Amit P Shah"
    Dim objFollowUp As Outlook.AppointmentItem
    Set objFollowUp = Application.CreateItem(olAppointmentItem)
    'Copies existing details from original Invite
    With objFollowUp
        .MeetingStatus = olMeeting
        .Subject = "Follow Up: " & obj.Subject
        .Body = obj.Body
        .Start = Now + 1 'Takes today's date and adds 1 day
        .End = DateAdd("n", obj.Duration, .Start)
        'Other
        .AllDayEvent = obj.AllDayEvent
        .BusyStatus = obj.BusyStatus
        .Categories = obj.Categories
        .Companies = obj.Companies
        .ForceUpdateToAllAttendees = obj.ForceUpdateToAllAttendees
        .Importance = obj.Importance
        .Location = obj.Location
        .OptionalAttendees = obj.OptionalAttendees
        .ReminderMinutesBeforeStart = obj.ReminderMinutesBeforeStart
        .ReminderOverrideDefault = obj.ReminderOverrideDefault
        .ReminderPlaySound = obj.ReminderPlaySound
        .ReminderSet = obj.ReminderSet
        .ReminderSoundFile = obj.ReminderSoundFile
        .ReplyTime = obj.ReplyTime
        .RequiredAttendees = obj.RequiredAttendees
        .Resources = obj.Resources
        .ResponseRequested = obj.ResponseRequested
        .Sensitivity = obj.Sensitivity
        .UnRead = obj.UnRead

        .Display
    End With
  End If

End Sub

Any help would greatly be appreciated. Many thanks in advance!


Solution



  • I'm not a specialist on this subject but i used to work and manipulate Outlook's AppointmentItem in C# and that's how i see the thing.

    Actually, if you try to copy the body of a meeting on another meeting, like you said, you will lose all the special formating, images, etc. The new body will only contain the caracters without format. I think you can't put formatted text on the body property, you have to use the rtfbody property or like you did when you copy the body of your original appointment, use the WordEditor property in the Inspector object.

    So, try to use the WordEditor of the new Item you're creating (like you did to take the original content) and to add content in it.

    That's what i had to do for putting formatted text in the body of an AppointmentItem in C#.

    I did something like that :

    Word.Document myDoc = myItem.GetInspector.WordEditor;
    Word.Paragraphs paragraphs = myDoc.Content.Paragraphs;
    
    Word.Paragraph para = paragraphs.Add();
    para.Range.Text = yourFormattedTextHere;
    

    After that, you may need to release the variables created, but i'm not sure about that.