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

移动指定的所选内容的结束位置,直到在文档中找到任何指定的字符。Moves the end position of the specified selection until any of the specified characters are found in the document.

语法Syntax

expressionexpression. MoveEndUntil( _Cset_ , _Count_ )

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

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
CsetCset 必需Required VariantVariant 一个或多个字符。One or more characters. 此参数区分大小写。This argument is case-sensitive.
CountCount 可选Optional VariantVariant 最大指定所选内容的移动的字符数。The maximum number of characters by which the specified selection is to be moved. 可以是数字, 也可以是wdForwardwdBackwardCan be a number or either wdForward or wdBackward. 如果 Count 是一个正数,则所选内容在文档中向前移动。If Count is a positive number, the selection is moved forward in the document. 如果是负数,则向后移动所选内容。If it is a negative number, the selection is moved backward. 默认值是 wdForwardThe default value is wdForward.

返回值Return value

LongLong

注解Remarks

此方法返回一个Long类型的值, 该值代表指定的所选内容的结束位置移动的字符数。This method returns a Long that represents the number of characters by which the end position of the specified selection was moved. 如果 Count 值大于 0 (零),则此方法返回的数字符移动加 1。If Count is greater than 0 (zero), this method returns the number of characters moved plus 1. 如果 Count 小于 0 (零),则此方法返回减 1 移动的字符数。If Count is less than 0 (zero), this method returns the number of characters moved minus 1. 如果没有找到 Cset 字符,所选内容不改变,并且该方法返回 0 (零)。If no Cset characters are found, the selection isn't changed and the method returns 0 (zero). 如果结束位置向后移至原来的起始位置之前,则将该起始位置设置为新的结束位置。If the end position is moved backward to a point that precedes the original start position, the start position is set to the new ending position.

如果是在文档中向前移动,则扩展所选内容。If the movement is forward in the document, the selection is expanded.

示例Example

以下示例在文档中向前扩展所选内容,直到找到字母“a”。This example extends the selection forward in the document until the letter "a" is found. 然后将所选文本扩展一个字符,以使其包含字母“a”。The example then expands the selection by one character to include the letter "a".

With Selection 
 .MoveEndUntil Cset:="a", Count:=wdForward 
 .MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend 
End With

以下示例在文档中向前扩展所选内容,直到找到制表符。This example extends the selection forward in the document until a tab is found. 如果在其后的 100 个字符中没有找到任何制表符,则不移动所选内容。If a tab character isn't found in the next 100 characters, the selection isn't moved.

char = Selection.MoveEndUntil(Cset:=vbTab, Count:=100) 
If char = 0 Then StatusBar = "Selection not moved"

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