A visitor to OutlookForums, PGilm is using VBA to create a meeting request and wanted to paste formatted text into the body.
While it's fairly straightforward if you are pasting into a mail item, you can't use HTMLBody or olHTMLFormat with non-mail items. You can use Word's 'Keep Source Formatting' paste command, provided you are using Word as the email editor. (It's the only editor in Outlook 2007 and newer.)
You will need to set a reference to the Word Object Model in the VB editor's Tools, References menu.
This sample code creates an appointment form with the clipboard contents pasted in the appointment body.
To remove the formatting, use wdFormatPlainText.
Sub PasteFormattedClipboard() On Error Resume Next Dim olCal: Set olCal = Application.CreateItem(1) olCal.Subject = "Testing " & Now olCal.Location = "Here" olCal.Display 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 = olCal ' 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 End Sub
The following is a list of the PasteAndFormat options available to use. wdFormatOriginalFormatting and wdFormatPlainText are the most frequently used paste formats that would cover most situations, however you can use other paste formats.
|wdSingleCellText||Pastes a single cell as text.|
|wdSingleCellTable||Pastes a single cell table as a separate table.|
|wdListContinueNumbering||Continues numbering of a pasted list from the list in the document.|
|wdListRestartNumbering||Restarts numbering of a pasted list.|
|wdTableInsertAsRows||Inserts a pasted table as rows between two rows in the target table.|
|wdTableAppendTable||Merges pasted cells into an existing table by inserting the pasted rows between the selected rows.|
|wdTableOriginalFormatting||Pastes an appended table without merging table styles.|
|wdChartPicture||Pastes an Excel chart as a picture.|
|wdChart||Pastes a Microsoft Excel chart as an embedded OLE object.|
|wdChartLinked||Pastes an Excel chart and links it to the original Excel spreadsheet.|
|wdFormatOriginalFormatting||Preserves original formatting of the pasted material.|
|wdFormatSurroundingFormattingWithEmphasis||Matches the formatting of the pasted text to the formatting of surrounding text.|
|wdFormatPlainText||Pastes as plain, unformatted text.|
|wdTableOverwriteCells||Pastes table cells and overwrites existing table cells.|
|wdListCombineWithExistingList||Merges a pasted list with neighboring lists.|
|wdUseDestinationStylesRecovery||Uses the styles that are in use in the destination document.|