Create event like textchanged for new object

C

codequest

I'd like to copy a shape, rename it, and then set up a mechanism that will
call a subroutine and pass a parameter to it when the text in the new shape
is changed.

I'm looking at two approaches, each with issues:

1) If I use the "TextChanged" event, I have to create a new event procedure
for every shape that I build. I've done this before in other code, but it's
complicated, and makes a bulky VBA module and maintenance difficulties.

2) If I create a RUNADDON procedure call formula in the new shape's
"TheText" cell, that event fires when the shape is moved, not just when the
text changes.

I'd like to use the second approach, and somehow get around the fact that
the event fires too much.

Any suggestions on how to get the effect using the second approach, while
limiting the event action to just when the text changes? (Maybe filter out
other events? Test for the TextChanged event in called subroutine?....other
thoughts that reveal my very limited knowledge of how these things work....
:)

Thanks!
 
J

JuneTheSecond

How would you like to use "Document_ShapeExitedTextEdit" event
in place of "TextChanged" event?
 
C

codequest

JuneTheSecond said:
How would you like to use "Document_ShapeExitedTextEdit" event
in place of "TextChanged" event?

That looks like the right event. However, I believe I would still need to
create an event procedure for each new shape that I build, rather than have
the event call built into the shape (like the TheText event).

Do you know of any sources of information and examples for creating event
procedures? Such as how to use the "Add" method? Thanks!
 
J

JuneTheSecond

You don't need to create an event procedure for each new shape.
Please try next macro in the module "ThisDocument".
Private Sub Document_ShapeExitedTextEdit(ByVal Shape As IVShape)
MsgBox Shape & " text changed to " & Shape.Text & " !!"
End Sub
Msgbox appears for any shape you chage the text in the document.
 
C

codequest

JuneTheSecond said:
You don't need to create an event procedure for each new shape.
Please try next macro in the module "ThisDocument".
Private Sub Document_ShapeExitedTextEdit(ByVal Shape As IVShape)
MsgBox Shape & " text changed to " & Shape.Text & " !!"
End Sub
Msgbox appears for any shape you chage the text in the document.

Way cool! This should open up that avenue, so I'll definitely give it a
try. BTW, is there a simple way to identify the name of the shape for which
the event occurs, at the time the event occurs? For example, will it be
"Selection?" Thanks!
 
C

codequest

codequest said:
Way cool! This should open up that avenue, so I'll definitely give it a
try. BTW, is there a simple way to identify the name of the shape for which
the event occurs, at the time the event occurs? For example, will it be
"Selection?" Thanks!

To answer my own question, yes, this works.

Private Sub Document_ShapeExitedTextEdit(ByVal Shape As IVShape)
MsgBox Shape & " text changed to " & Shape.Text & " !!"
Set shp1 = ActiveWindow.Selection.Item(1)
Debug.Print shp1.Name
End Sub

Thanks again!
 
C

codequest

codequest said:
To answer my own question, yes, this works.

Private Sub Document_ShapeExitedTextEdit(ByVal Shape As IVShape)
MsgBox Shape & " text changed to " & Shape.Text & " !!"
Set shp1 = ActiveWindow.Selection.Item(1)
Debug.Print shp1.Name
End Sub

Thanks again!


And the better answer is the, "Shape" in the procedure declaration is the
shape as an object. Cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top