【问题标题】:Outlook VBA: Using Word Inspector to create a Follow Up Meeting InviteOutlook VBA:使用 Word Inspector 创建后续会议邀请
【发布时间】:2018-03-28 03:20:07
【问题描述】:

我正在 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

任何帮助将不胜感激。提前谢谢了!

【问题讨论】:

    标签: vba outlook ms-word copy-paste


    【解决方案1】:



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

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

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

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

    我做了类似的事情:

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

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

    【讨论】:

      猜你喜欢
      • 2021-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-09
      • 2015-04-14
      • 1970-01-01
      • 1970-01-01
      • 2011-06-16
      相关资源
      最近更新 更多