Data Shape and Text input field mutually exclusive

Started by Machine, April 03, 2020, 10:04:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Machine

I really hope Mods/Admin won't mind me digging out this thread...

I decided to tackle this problem again, this time with VBA, since the initial solutions is not the most elegant one.


VBA:

Option Explicit
Global TheTextInEdit As Boolean
Global ShapeDataInEdit As Boolean

Public Sub TheTextChanged(shp As Visio.Shape, field As String)
    ''Prevent from running this function when the other one is in work
    If (ShapeDataInEdit) Then Exit Sub
    TheTextInEdit = True
   
    Dim sel As Selection: Set sel = ActiveWindow.Selection
   
    If sel.PrimaryItem.Characters <> sel.PrimaryItem.Cells(field).ResultStr("") Then
        sel.PrimaryItem.Cells(field).FormulaU = Chr(34) & sel.PrimaryItem.Text & Chr(34)
    End If
   
    TheTextInEdit = False
End Sub

Public Sub ShapeDataChanged(shp As Visio.Shape, field As String)
    'Prevent from running this function when the other one is in work'
    If (TheTextInEdit) Then Exit Sub
    ShapeDataInEdit = True
   
    Dim sel As Selection: Set sel = ActiveWindow.Selection
   
    If sel.PrimaryItem.Text <> sel.PrimaryItem.Cells(field).ResultStr("") Then
        sel.PrimaryItem.Text = sel.PrimaryItem.Cells(field).ResultStr("")
    End If
   
    ShapeDataInEdit = False
End Sub


If anyone have cleaner/faster solution, please write it below.