【问题标题】:Save changes to a mailitem's inspector将更改保存到 mailitem 的检查器
【发布时间】:2015-01-03 12:43:21
【问题描述】:

我正在 PowerShell 2.0 中编写一个脚本,以使用 Outlook COM 对象在日历上创建一堆约会。我的代码可以正常工作,但最终用户要求将格式化表格添加到约会正文中。在尝试了其他几个选项后,我最终使用Mailitem.GetInspector.WordEditor 来编辑正文。但是,我无法在不打开 Outlook 中的项目并点击保存的情况下保存正文。以下是相关代码:

$newCalenderItem = $folder.Items.Add()
$newCalenderItem.Subject = $appt.Subject
$newCalenderItem.Location = $location
$newCalenderItem.Start = $d.AddHours($timeSlot.Time)
$newCalenderItem.Duration = 60 * $timeSlot.Duration
$newCalenderItem.BusyStatus = 2
$newCalenderItem.ReminderSet = $false
$newCalenderItem.Categories = $appt.Category
$newCalenderItem.Body = ""
if ($appt.BodyFile) {
    $newCalenderItem.GetInspector.WordEditor.Range().InsertFile("C:\Body.rtf", "", $false, $false, $false)

    #this doesn't save it
    $newCalenderItem.GetInspector.WordEditor.Close([ref] -1)
}
#this saves everything but the body
$newCalenderItem.Save()

我尝试过GetInspector.Close()WordEditor.Close()WordEditor.Save(),它们会弹出另存为对话框。有谁知道如何做到这一点?

【问题讨论】:

    标签: powershell com outlook powershell-2.0


    【解决方案1】:

    您需要设置 AppointmentItem.RtfBody 属性 - Outlook 约会、任务和联系人使用 RTF 而不是 HTML。您可以将您的 RTF 文件读入一个变体字节数组以传递给 RtfBody 属性。

    【讨论】:

    • 我正在编辑 MailItem,而不是约会。我曾尝试编辑 RTFBody 但总是收到错误 Exception setting "RTFBody": "Value does not fall within the expected range." 所以我转向使用 MailItem 的检查器。
    • 请出示您的代码。您是否创建了一个变体字节数组来保存数据?
    【解决方案2】:

    我自己在检查员的成员周围挖掘并想发布答案,如果有人发现这个是为了寻找他们自己的问题。 您需要保存检查员的 CurrentItem 而不是检查员本身。

    $newCalenderItem.GetInspector.CurrentItem.Save()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-15
      • 2011-03-09
      • 2010-12-24
      • 2020-02-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-28
      相关资源
      最近更新 更多