Outlook VBA:使用Word Inspector创建后续会议邀请

时间:2017-05-02 21:58:30

标签: vba outlook ms-word copy-paste

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

我的问题在于邀请的主体;所有格式和图片都丢失了。因此,我需要使用Word Inspector对象来保留任何特殊的格式和图像。我想出了使用Word并录制宏的代码。

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

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

非常感谢任何帮助。提前谢谢了!

1 个答案:

答案 0 :(得分:0)



我不是这个主题的专家,但我曾经在C#中工作和操作Outlook的AppointmentItem,这就是我看到的东西。

实际上,如果你试图在另一次会议上复制会议的主体,就像你说的那样,你将失去所有特殊的格式,图像等。 新主体只包含没有格式的字符。 我认为您不能将格式化文本放在body属性上,您必须使用 rtfbody 属性,或者像复制原始约会的主体时那样,使用 WordEditor 属性。

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

这就是我必须要做的就是将格式化文本放在C#中的AppointmentItem主体中。

我做了类似的事情:

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

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

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