Master.CellChanged Event issue

Started by metuemre, July 19, 2016, 10:00:58 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

metuemre

I'm trying to detect cell changes based on specific conditions. To track the changes on the shapes with the same master I tried to use Master.CellChanged event but I couldn't make it work. Below is the code that I used for test. I changed Prop.IN1 value of shape named "ALARM.238" but nothing happened. When I try it with Shape.CellChanged event I can see this change. What is wrong with this code below?


Private WithEvents vsomst As Visio.Master

Public Sub Change()

Set vsomst = ActiveDocument.Masters.Item("ALARM")

End Sub

Private Sub vsomst_CellChanged(ByVal vsoCell As IVCell)

Debug.Print vsoCell.Shape.Name

End Sub



Maybe Master.CellChanged event tracks the changes on the master in the Document stencil. I tried that also but again event didn't trigger.

Did anyone used this event with success? Any kind of idea will help, thanks.

Surrogate

Look at example in article Cell.CellChanged Event (Visio)
it is event for application-object, not master-object

metuemre

There are different types of CellChanged events. Please see the links below

https://msdn.microsoft.com/en-us/library/office/ff768439.aspx
https://msdn.microsoft.com/en-us/library/office/ff766365.aspx

If you want to track changes for a specific shape you can use sample code below and it works. But I couldnt make it work for a specific master


Private WithEvents vsoshp As Visio.Shape

Public Sub Change()

Set vsoshp = ActiveWindow.Selection(1)

End Sub

Private Sub vsoshp_CellChanged(ByVal vsoCell As IVCell)

Debug.Print vsoCell.Shape.Name

End Sub




Surrogate

ok, you are right ! Which event you want track: changes of master's cells in document stencil or changes of shape's cells in page (shape based on master) ?

metuemre

I want to track  changes of shape's cells in ActiveDocument (shape based on master). I need to know the changes on non-active pages as well.

Surrogate

#5
try this code please
Private WithEvents vsoApplication As Visio.Application

Public Sub CellChanged_Example()

'Set a module-level variable to trap application-level events.
Set vsoApplication = Application

End Sub

Private Sub vsoApplication_CellChanged(ByVal vsoCell As IVCell)
Dim sh As Shape
' define selected shape
Set sh = vsoCell.Shape
' exception for shapes not based on any master
If Not sh.Master Is Nothing Then

If sh.Master = "ALARM" Then Debug.Print sh.Name & " " & vsoCell.Name & " changed to =" & vsoCell.Formula
End If

End Sub

metuemre

Thanks Surrogate but I dont want to read the changes from an Application level event since every change on the Application  triggers this event and lots of things happens on my application at the same time.

Right now I'm using this event but sometimes I can't detect the changes because of unrelevant trigger of application.cellchanged event and this results in wrong outputs in my calculations.

That's why I'm looking for a solution which is specific to a master.

wapperdude

#7
The "master" resides only on the stencil which contains it.  Any changes to the master only occur if it is editted from the stencil .  Upon drag and drop, Visio places a copy in the Document stencil, and a copy on the active drawing page.  The page placements will refer back to the Document stencil.

Typically, changes to the master on the stencil are rare...the stencil is typically read only.  Changes to shapes in document stencil are usually intentional, with the goal of making all copies on document pages identical.  Changes at the page level are "localized" and do not propagate throughout the other pages.

Note, editting the master on the stencil will not automatically update the shapes on the drawing pages.  Only changes to document stencil will do that.  To make changes to be universally available for future use in other documents and all shapes within active document requires changes be applied to both document and master stencils.

HTH.
Wapperdude
Visio 2019 Pro

metuemre

Thanks wapperdude for the explanation. Let me rephrase my question then.

What would be the best way to detect specific cell change of specific shapes which belongs to same master other than application.cellchanged event?

Right now I'm using application.cellchanged event but as i said lots of things happen at the same time and I miss some of the important changes while transfering data to an Excel sheet. Instead of filtering them on the application level, I hope there is a way to filter them on master or collection of shapes level.

Please see my event code below. Any suggestion is appreciated.


Private WithEvents vsoApplication As Visio.Application

Public Sub Change ()

  Set vsoApplication = Application

End Sub

Private Sub vsoApplication_CellChanged(ByVal vsoCell As IVCell)

If vsoCell.Shape.Master.NameU = "DI_Line" Then

    If vsoCell.Name = "Prop.Value" Then

       'Do something

ElseIf vsoCell.Shape.Master.NameU = "AI_Line" Then

    If vsoCell.Name = "Prop.Value" Then
     
       ' Do something else

ElseIf vsoCell.Shape.Master.NameU = "ONESHOT" Then
   
        If vsoCell.Name = "Prop.IN1" Then

         ' Do something else

ElseIf vsoCell.Shape.Master.NameU = "TD_ON" Then
   
        If vsoCell.Name = "Prop.IN1" Then

          ' Do something else

End if

End sub


wapperdude

Visio 2019 Pro

metuemre

I found an interesting solution to my problem.

Shape.CellChanged event monitors the changes for one shape and Application.CellChanged event monitors all the changes in the application but I needed to monitor changes on a set of shapes with the same master. To accomplish that I wrote a macro which will run on drop event of a master shape. This macro creates a Shape.CellChanged event in ThisDocument object. A macro which creates another macro :) If the shape is deleted I delete the corresponding event code with Document.BeforeSelectionDelete event.

Maybe it is not the ideal solution but it works.

Thanks you all.