从当前光标位置创建范围Word 2010 VBA [英] Create Range from current cursor position Word 2010 VBA

查看:164
本文介绍了从当前光标位置创建范围Word 2010 VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有用户表单的.docm文档.在用户表单上,我有一个按钮,需要在文档中最后一个已知的光标位置插入一些内容(例如文本,用于启动程序).为此,我想创建一个范围.

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?

推荐答案

  • Selection是文档中的当前位置.
  • Selection.Range是当前Selection的Range对象.
  • Range.StartRange对象的起始位置(返回或设置Long).
    • 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"
      

      这篇关于从当前光标位置创建范围Word 2010 VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆