InsertAfter 方法 (Word)Selection.InsertAfter method (Word)

将指定文本插入范围或所选内容的末尾。Inserts the specified text at the end of a range or selection.

语法Syntax

expressionexpression. InsertAfter( _Text_ )

expression:必需。expression Required. 表示 Selection 对象的变量。A variable that represents a Selection object.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
TextText 必需Required StringString 要插入的文本。The text to be inserted.

备注Remarks

使用此方法后,所选内容将扩展以包含新文本。After using this method, the selection expands to include the new text.

您可以通过使用 Visual Basic Chr函数和InsertAfter方法来插入引号、制表符和不间断连字符等字符。You can insert characters such as quotation marks, tab characters, and nonbreaking hyphens by using the Visual Basic Chr function with the InsertAfter method. 您还可以使用下面的 Visual Basic 常量: vbCrvbLfvbCrLfvbTabYou can also use the following Visual Basic constants: vbCr, vbLf, vbCrLf and vbTab.

如果对引用整个段落的所选内容使用此方法,则在末段标记之后插入文本(插入文本将出现在下一段落的开头)。If you use this method with a selection that refers to an entire paragraph, the text is inserted after the ending paragraph mark (the text will appear at the beginning of the next paragraph). 要在段尾插入文本,请先确定终点,再从该位置减去 1(因为段落标记是一个字符),如以下示例所示。To insert text at the end of a paragraph, determine the ending point and subtract 1 from this location (the paragraph mark is one character), as shown in the following example.

ActiveDocument.Range( _ 
 ActiveDocument.Paragraphs(1).Range.Start, _ 
 ActiveDocument.Paragraphs(1).Range.End - 1) _ 
 .Select 
 
Selection.InsertAfter _ 
 " This is now the last sentence in paragraph one."

然而,如果所选内容以一个段落标记结尾,而该段落标记正好又是文档的末尾,则 Microsoft Word 在末段标记前插入文本,而不是在文档末尾创建一个新段落。However, if the selection ends with a paragraph mark that also happens to be the end of the document, Microsoft Word inserts the text before the final paragraph mark rather than creating a new paragraph at the end of the document. 同样,如果所选内容是书签,则 Word 会插入指定文本,但是不会扩展所选内容或书签使其包含新文本。Also, if the selection is a bookmark, Word inserts the specified text but does not extend the selection or the bookmark to include the new text.

示例Example

以下示例在所选内容的末尾插入文本,然后将所选内容折叠到插入点。This example inserts text at the end of the selection and then collapses the selection to an insertion point.

With Selection 
 .InsertAfter "appended text" 
 .Collapse Direction:=wdCollapseEnd 
End With

另请参阅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.