Event when custom property value is changed

L

Leland

Is there any event that is triggered when a value of a custom property has
changed. I have a custom value called "Color" and when a user changes the
value, I want to automatically change the color of the shape. If not an
event, is there any other way of knowing when a value changes? (e.g.
formula in the shapesheet, etc.)

Thanks,
Dave
 
A

Al Edlund

a custom property change is like every other cell change, it's only
necessary to check the first part of the cell name for the "prop." portion.
I use use the pagObj_CellChanged(ByVal Cell As IVCell) event for my
monitoring.
Al
 
M

msnews.microsoft.com

Okay, I see the documentation on it now and I've copied the example from
MSDN but I can't get the event to fire. There must be something else I'm
missing. Any suggestions as to where to look?

Dave
 
A

Al Edlund

You need to put something like this at the beginning of the module

' for event management
Private WithEvents pagObj As Visio.Page
Private WithEvents appObj As Visio.Application
Private WithEvents shpObj As Visio.Shape
Private WithEvents winObj As Visio.Window
Private WithEvents DocObj As Visio.Document
 
L

Leland

Here's the code I have. I have it in "Class Modules" and have named my
class module "ShapeSink".

Dim WithEvents m_shpObj As Visio.Shape
Public Sub InitWith(ByVal aShape As Visio.Shape)
Set m_shpObj = aShape
End Sub
Private Sub m_shpObj_CellChanged(ByVal Cell As Visio.IVCell)
MsgBox ("test")
End Sub

I tried adding the lines of code you sent but still nothing. What am I
doing wrong?

Dave
 
A

Al Edlund

Put the event declaration and the sink definition in the thisdocument and
try it this way,
Al

Private WithEvents pagObj As Visio.Page

Private Sub Document_DocumentOpened(ByVal doc As Visio.IVDocument)

' Bind the pagObj variable to the ActivePage in Visio
' This will allow event handling to start to happen
Set pagObj = Visio.ActivePage

end sub

Private sub pagObj_CellChanged(ByVal Cell As IVCell)
msgbox cell.name
end sub
 
L

Leland

That worked. Thanks. It does puzzle me why the MSDN example didn't work
though.

Dave
 
V

Viorel Farcas

Hi

The msdn example didnt work because the m_shpObj was not initialized.
Try creating an instance of the class you made, and then calling InitWith
for a given shape. Next , change a cell of that shape.

Regards
 
M

Mark Nelson [MS]

You could also do this without code by putting a formula in the FillForegnd
cell that references the value in your Color custom property. If your
property uses words for colors instead of the Visio color values, use the
Lookup() function to translate.
 
L

Leland

Cool! That's exactly what I was looking for. I like this much better than
using event processing.

Dave
 

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