Create Range from current cursor position Word 2010 VBA

笑着哭i 提交于 2019-11-30 14:24:54

问题


I have a .docm document with a user form. On the user form I have a button that needs to insert something (some text, for starter) at the last known cursor position in the document. For this, I want to create a range.

How can I get the starting position for this range?


回答1:


  • Selection is the current position in the document.
  • Selection.Range is the Range object of the current Selection.
  • Range.Start is the start position of a Range object (returns or sets a Long).

If you combine those three you get the cursor position (or the start of the selection if you have text selected):

Selection.Range.Start

If you only want to enter text att the cursor position the following will do:

Selection.TypeText "Test"


来源:https://stackoverflow.com/questions/16807860/create-range-from-current-cursor-position-word-2010-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!