word vba 控制光标常用代码
Selection.MoveDown Unit:=wdLine, Count:=1'光标下移一行’选中光标所在行With Selection.HomeKey Unit:=wdLine, Extend:=wdExtend.MoveEnd Unit:=wdLine, Count:=1End With
移动光标至文档开始Selection.HomeKey unit:=wdStory下面的供参考:Sub MoveToCurrentLineStart()'移动光标至当前行首Selection.HomeKey unit:=wdLineEnd SubSub MoveToCurrentLineEnd()'移动光标至当前行尾Selection.EndKey unit:=wdLineEnd SubSub SelectToCurrentLineStart()'选择从光标至当前行首的内容Selection.HomeKey unit:=wdLine, Extend:=wdExtendEnd SubSub SelectToCurrentLineEnd()'选择从光标至当前行尾的内容Selection.EndKey unit:=wdLine, Extend:=wdExtendEnd SubSub SelectCurrentLine()'选择当前行Selection.HomeKey unit:=wdLineSelection.EndKey unit:=wdLine, Extend:=wdExtendEnd SubSub MoveToDocStart()'移动光标至文档开始Selection.HomeKey unit:=wdStoryEnd SubSub MoveToDocEnd()'移动光标至文档结尾Selection.EndKey unit:=wdStoryEnd SubSub SelectToDocStart()'选择从光标至文档开始的内容Selection.HomeKey unit:=wdStory, Extend:=wdExtendEnd SubSub SelectToDocEnd()'选择从光标至文档结尾的内容Selection.EndKey unit:=wdStory, Extend:=wdExtendEnd SubSub SelectDocAll()'选择文档全部内容(从WholeStory可猜出Story应是当前文档的意思)Selection.WholeStoryEnd SubSub MoveToCurrentParagraphStart()'移动光标至当前段落的开始Selection.MoveUp unit:=wdParagraphEnd SubSub MoveToCurrentParagraphEnd()'移动光标至当前段落的结尾Selection.MoveDown unit:=wdParagraphEnd SubSub SelectToCurrentParagraphStart()'选择从光标至当前段落开始的内容Selection.MoveUp unit:=wdParagraph, Extend:=wdExtendEnd SubSub SelectToCurrentParagraphEnd()'选择从光标至当前段落结尾的内容Selection.MoveDown unit:=wdParagraph, Extend:=wdExtendEnd SubSub SelectCurrentParagraph()'选择光标所在段落的内容Selection.MoveUp unit:=wdParagraphSelection.MoveDown unit:=wdParagraph, Extend:=wdExtendEnd SubSub DisplaySelectionStartAndEnd()'显示选择区的开始与结束的位置,注意:文档第1个字符的位置是0MsgBox ("第" & Selection.Start & "个字符至第" & Selection.End & "个字符")End SubSub DeleteCurrentLine()'删除当前行Selection.HomeKey unit:=wdLineSelection.EndKey unit:=wdLine, Extend:=wdExtendSelection.DeleteEnd SubSub DeleteCurrentParagraph()'删除当前段落Selection.MoveUp unit:=wdParagraphSelection.MoveDown unit:=wdParagraph, Extend:=wdExtendSelection.DeleteEnd Sub
赞 (0)
