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

当在文档中找到任何指定的字符时,移动指定的所选内容的起始位置。Moves the start position of the specified selection while any of the specified characters are found in the document.

语法Syntax

expressionexpression. MoveStartWhile( _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. 可以是一个数字, 也可以是wdForwardwdBackward常量。Can be a number or either the wdForward or wdBackward constant. 如果 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.

备注Remarks

在找到 Cset 中的任何字符时移动所选内容的起始位置。While any character in Cset is found, the start position of the selection is moved. 此方法返回所选内容的起始位置作为Long 类型的值移动的字符数。This method returns the number of characters that the start position of the selection moved as a Long value. 如果没有找到 Cset 字符,不改变所选内容,并且此方法返回 0 (零)。If not Cset characters are found, the selection isn't changed and the method returns 0 (zero). 如果起始位置向前移动到超出原来的结束位置的某个位置,该结束位置设置为新的起始位置。If the start position is moved forward to a position beyond the original end position, the end position is set to the new start position.

示例Example

当找到空格时,以下示例在文档中向后移动所选内容的起始位置。This example moves the start position of the selection backward through the document while the space character is found.

Selection.MoveStartWhile Cset:=" ", Count:=wdBackward

当 Count 小于或等于 10,并且找到从"a"到"h"之间的一个字母时,以下示例将所选内容的起始位置向后移动。This example moves the start position of the selection backward through the document while Count is less than or equal to 10 and any letter from "a" through "h" is found.

Selection.MoveStartWhile Cset:="abcdefgh", Count:=-10

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