问题
I am trying to schedule a meeting automatically from Excel.
It is simple, unless you are trying to format the body text.
I made some research about GetInspector.
It looks like I have to copy the text from another place, but the commands I found are incorrect or not functional. Even trying to format it as RTF, but .RTFBody is not a property of the AppointmentItem object
Find my code:
Dim oApp As Object
Dim oMail As Object
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(1)
With oMail
.Subject = ""
.Location = ""
'.Start =
'.Duration =
.body = " < not formattable text >"
.display
End With
Set oApp = Nothing
Set oMail = Nothing
回答1:
I once asked this question, and got an answer here (http://www.slipstick.com/developer/code-samples/paste-formatted-text-vba/)
Try the following. You will need to set a reference to the Word Object Model, and the formatted text should be stored in the clipboard, and note, you have to have the .display
line before the .body
line for there to be something to work with:
Dim oApp As Object
Dim oMail As Object
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(1)
With oMail
.Subject = ""
.Location = ""
'.Start =
'.Duration =
' .body = " < not formattable text >"
.display
End With
Dim objItem As Object
Dim objInsp As Outlook.Inspector
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objSel As Word.Selection
Set objItem = oMail ' Application.ActiveInspector.currentItem
Set objInsp = objItem.GetInspector
Set objDoc = objInsp.WordEditor
Set objWord = objDoc.Application
Set objSel = objWord.Selection
objSel.PasteAndFormat (wdFormatOriginalFormatting)
'objSel.PasteAndFormat (Word.WdRecoveryType.wdFormatOriginalFormatting)
Set objItem = Nothing
Set objInsp = Nothing
Set objDoc = Nothing
Set objWord = Nothing
Set objSel = Nothing
Set oApp = Nothing
Set oMail = Nothing
Hth
来源:https://stackoverflow.com/questions/34665581/formatting-appointment-body