我正在使用Outlook COM對象在PowerShell 2.0中創建一組約會,以在日曆上創建一組約會。我的代碼完全可以工作,但最終用戶請求將格式化的表格添加到約會的正文中。在嘗試了其他幾個選項之後,我最終使用了Mailitem.GetInspector.WordEditor
來編輯正文。但是,我無法在不打開Outlook中的項目並保存的情況下保存正文。下面是相關代碼:將更改保存到mailitem的檢查員
$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()
它會彈出一個另存爲對話框。有誰知道如何做到這一點?
我正在編輯MailItem,而不是預約。我試圖編輯RTFBody,但總是得到錯誤'異常設置「RTFBody」:「值不在預期範圍內。」所以我轉向使用MailItem的檢查器。 – 2014-11-07 16:54:35
請顯示您的代碼。您是否創建了一個字節變量數組來保存數據? – 2014-11-08 17:38:51