如何在VBA visio中使用TextChanged事件? [英] How do I use TextChanged event in VBA visio?

查看:234
本文介绍了如何在VBA visio中使用TextChanged事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与这个问题有关
在完成编辑后,如何以编程方式/自动更改Visio形状文本的文本格式?



我试图使用一些代码,当编辑一个形状的文本
由于某些原因,如所描述的那样,在某些情况下,我无法隔离代码是无止尽的执行。
这可能是因为脚本在循环中调用自身。每次编辑形状的文本时都应该执行代码。代码本身会改变文本的颜色。我想这将被视为一个新的文本更改等等。



我正在考虑使用名为TextChanged的事件。根据文档,这应该在用户完成编辑时执行代码
http://msdn.microsoft.com/en-us/library/office/ff768749.aspx



我找不到一个例子在VBA中使用这样的事件,这里是我需要你的帮助
提前感谢
Uni



这是我测试的方式:
我使用CallThis('ThisDocument.warning)从该形状的TheText事件调用以下过程(可通过形状表获得)



子警告(oShape As Visio
MsgBox(Text edited)
End Sub



如果我明星编辑形状的文本,这将被执行三次我按空格键(现有文本添加一个空格)

解决方案

p>

打开代码编辑器
在项目浏览器中选择ThisDocume nt
下一步在ObjectWindow中选择文档
然后在方法下拉框中选择ShapeExitedTextEdit
您将看到如下所示的框架过程



Private Sub Document_ShapeExitedTextEdit(ByVal oShape As IVShape)



End Sub



每次当编辑完成


时,您都要执行

This is related to this question How do I programmatically/automatically change the text formatting for the text of a Visio shape after I am done with the editing?

There I tried to use some code that would be executed when the text of a shape is edited For some reasons, as described there, in some situations which I could not isolate the code is executed endlessly. That is probably because the script calls itself in a loop. The code is supposed to be executed every time the text of the shape is edited BUT the code itself changes the color of the text. I guess that would count as a new text change and so on.

I am thinking about using the event called TextChanged. According with the documentation this should execute the code when the user finished the editing http://msdn.microsoft.com/en-us/library/office/ff768749.aspx

I could not find a example of using such event in VBA and here is where I need your help thanks in advance Uni

This is how I tested: I used CallThis('ThisDocument.warning") to call the procedure below from "TheText" event of that shape (available via the shapesheet)

Sub warning(oShape As Visio.Shape) MsgBox ("Text edited") End Sub

This gets executed like three times if I star editing the text of a shape and I press the space key (adding a space to the existing text)

解决方案

Ok here is how you do it:

Open the Code editor In the Project explorer select "ThisDocument" Next in the ObjectWindow select Document Then in the Method dropdown box select ShapeExitedTextEdit You will see a skeleton procedure like below

Private Sub Document_ShapeExitedTextEdit(ByVal oShape As IVShape)

End Sub

There is where you add the code that you want to be executed every time when the editing if finished

这篇关于如何在VBA visio中使用TextChanged事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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