在word vba运行时创建一个新的选择对象
我之前问过这个问题,但我认为我还不够清楚。
我需要编写一个 Word VBA 宏,该宏将提示用户在宏开始运行后突出显示一些文本,然后处理新的选择。 此过程将在宏内重复未知次数。
我遇到的唯一问题是弄清楚如何让 VBA 宏“暂停”并允许用户做出此选择。 如果有人熟悉 AutoCAD VBA,我正在寻找与 AcadSelectionSet.SelectOnScreen 方法等效的方法。 这看起来如此明显和基本,但我在 Microsoft 帮助文件或在线搜索中找不到任何内容来告诉我如何做到这一点。 如果可以的话请帮忙!
I asked this question previously but I don't think I was clear enough.
I need to write a Word VBA macro which will prompt the user to select some text by highlighting it after the macro has started running and then to process the new selection. This process will repeat an unknown number of times within the macro.
The only problem I have is figuring out how to get the VBA macro to 'pause' and allow the user to make this selection. If anyone is familiar with AutoCAD VBA, I am looking for the equivalent of the AcadSelectionSet.SelectOnScreen
method. This seems so obvious and fundamental, but I just can't find anything in the Microsoft help files or searching online that shows me how to do this. Please help if you can!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否应该查看
Application
对象的WindowSelectionChange
事件?在特殊的
ThisDocument
模块中,您需要如下代码:显然,将
MsgBox
替换为有用的代码,并使用Sel
参数来访问选择。 如果您想尝试其他事件,请使用ThisDocument
模块顶部的下拉菜单进行设置,您需要在普通代码模块中使用如下宏:
在
setUpApp
之后> 运行一次后,每当选择更改时都会触发app_WindowSelectionChange
事件Should you perhaps be looking at the
WindowSelectionChange
event of theApplication
object?In the special
ThisDocument
module, you need code like this:Obviously replace the
MsgBox
with useful code and use theSel
parameter to access the selection. If you want to try other events then use the dropdowns at the top of theThisDocument
moduleTo set it up, you need a macro like this in a normal code module:
After
setUpApp
has run once, theapp_WindowSelectionChange
event will be triggered whenever the selection changes您可以使用无模式表单让宏继续运行,直到满足特定条件:
表单设计器:
表单代码:
另一个代码模块:
You could use a modeless form to let your macro keep running until a certain condition was met:
Form designer:
Form code:
Another code module: