word vba怎样把光标定位到指定字符串的位置?
展开全部移动光标至文档开始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
word vba 怎么获取当前光标所在页码,并获取该页有多少行
Sub Macro2()Dim r, p, r0, p0, rr, ppp= Selection.Information(wdActiveEndPageNumber) '当前页码r= Selection.Information(wdFirstCharacterLineNumber) '当前行'数行数p0 = prr = rDoSelection.MoveDown Unit:=wdLine, Count:=1pp = Selection.Information(wdActiveEndPageNumber)r0 = Selection.Information(wdFirstCharacterLineNumber)If pp > p Then'退回原处Selection.MoveUp Unit:=wdLine, Count:=(rr - r + 1)Exit DoEnd IfIf rr = r0 Then'退回原处Selection.MoveUp Unit:=wdLine, Count:=(rr - r)Exit DoEnd Ifrr = r0LoopMsgBox "当前页码:" & p & vbCrLf &; "本页总行数:" & rrEnd Sub 申请加悬赏分!!!
VBA word 光标如何移动段尾
你是说获取上面的项目编号吗?试过项目编号获取没成功。
但段落编号我搞定了:a=ActiveDocument.Range(0, selection.End).Paragraphs.Counta里面就是当时光标所在的段落号,举例,全文有10段,光标在第3段,返回值就是3。
VBA光标定位
Private Sub Worksheet_Change(ByVal Target As Range)r = Selection.Rowc = Selection,右键点工作表标签,选查看代码,粘贴到新开的窗口中。
关闭新窗口,回到Excel中.ColumnIf c < 17 ThenCells(r - 1, c + 1).SelectElseCells(r, 1).SelectEnd IfEnd Sub用法:复制以上代码给个代码...
如何通过VBA将光标定位新的一行
在Word中,将光标定位到当前页的页尾的快捷键是:End;在Word中,将光标定位到文档的尾部的的快捷键是:Ctrl + End。
还有,在Word中,将光标定位到当前页的页首的快捷键是:Home;在Word中,将光标定位到文档的首部的的快捷键是:Ctrl +Home。
转载请注明出处51数据库 » vba 记录word 光标位置
生活不止眼前的狗血