Outlook VBA:使用 Word Inspector 创建跟进会议邀请

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

我正在 Outlook 中创建一个 VBA 宏,它将复制现有的会议邀请并创建后续会议邀请。这应该相当容易,因为我拥有这个谜题的所有部分。

我的问题出在邀请正文上;所有格式和图片都丢失了。为此,我需要使用 Word Inspector object 来保留任何特殊格式和图像。我想通了使用 Word 和录制宏的代码。

所以我找到了使用 Word 检查器复制文本的代码,但我不确定如何将它粘贴到另一个邀请中。

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

请查看我当前的 Outlook 代码:

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

如有任何帮助,我们将不胜感激。提前谢谢了!



我不是这方面的专家,但我曾经在 C# 中工作和操作 Outlook 的 AppointmentItem,这就是我的看法。

实际上,如果您尝试将一个会议的正文复制到另一个会议上,如您所说,您将丢失所有特殊格式、图像等。 新主体将只包含没有格式的字符。 我认为你不能将格式化文本放在正文 属性 上,你必须使用 rtfbody 属性 或者像你复制正文时所做的那样原来约会,使用WordEditor 属性 Inspector object.

因此,尝试使用您正在创建的新项目的 WordEditor(就像您获取原始内容一样)并在其中添加内容。

这就是我在 C# 中将格式化文本放入 AppointmentItem 正文所要做的。

我做了类似的事情:

Word.Document myDoc = myItem.GetInspector.WordEditor;
Word.Paragraphs paragraphs = myDoc.Content.Paragraphs;

Word.Paragraph para = paragraphs.Add();
para.Range.Text = yourFormattedTextHere;

之后,您可能需要释放创建的变量,但我不确定。