How do I use TextChanged event in VBA visio?

邮差的信 提交于 2019-12-12 02:37:30

问题


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)


回答1:


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



来源:https://stackoverflow.com/questions/20688868/how-do-i-use-textchanged-event-in-vba-visio

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