FormattedText 属性 (Word)Selection.FormattedText property (Word)

返回或设置一个**Range** 对象, 该对象包含指定区域或选定内容中的格式化文本。Returns or sets a Range object that includes the formatted text in the specified range or selection. 读/写。Read/write.

语法Syntax

expressionexpression. FormattedText

_表达式_一个代表**Selection** 对象的变量。expression A variable that represents a Selection object.

说明Remarks

此属性返回一个**range** 对象, 其中包含指定区域或所选内容中的字符格式和文本。This property returns a Range object with the character formatting and text from the specified range or selection. 如果在区域或所选内容中有一个段落标记,则 Range 对象中包含段落格式。Paragraph formatting is included in the Range object if there is a paragraph mark in the range or selection.

当设置此属性时,区域中的文本将替换带格式的文本。When you set this property, the text in the range is replaced with formatted text. 如果不想替换现有的文本, 请在使用此属性之前使用Collapse方法 (请参见第一个示例)。If you don't want to replace the existing text, use the Collapse method before using this property (see the first example).

示例Example

本示例复制文档中的第一个段落,包含段落的格式,并在插入点插入带格式的文字。This example copies the first paragraph in the document, including its formatting, and inserts the formatted text at the insertion point.

Selection.Collapse Direction:=wdCollapseStart 
Selection.FormattedText = ActiveDocument.Paragraphs(1).Range

本示例将选定内容的文字和格式复制到新文档。This example copies the text and formatting from the selection into a new document.

Set myRange = Selection.FormattedText 
Documents.Add.Content.FormattedText = myRange

另请参阅See also

Selection 对象Selection Object

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.