从当前光标位置创建范围 Word 2010 VBA
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16807860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create Range from current cursor position Word 2010 VBA
提问by Silviu Preda
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.
我有一个带有用户表单的 .docm 文档。在用户表单上,我有一个按钮需要在文档中最后一个已知的光标位置插入一些东西(一些文本,对于初学者)。为此,我想创建一个范围。
How can I get the starting position for this range?
我怎样才能获得这个范围的起始位置?
回答by Olle Sj?gren
Selection
is the current position in the document.Selection.Range
is the Range object of the currentSelection
.Range.Start
is the start position of aRange
object (returns or sets a Long).
Selection
是文档中的当前位置。Selection.Range
是当前 的 Range 对象Selection
。Range.Start
是Range
对象的开始位置(返回或设置一个 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"