I suppose I should explain what I mean by dirty text first 🙂
I often display the value of a Shape Data row in Visio text, but sometimes the solution requires that the value is also editable. This is ok if the client accepts that all editing is done with the Shape Data window or dialog, but not if the user more naturally wants to edit the text in the shape. In my current solution, I want to pass the manually edited text to another process for checking, and then only update the Shape Data row when validated or accepted, before re-setting the text with the inserted field. My first task was to spot with text had been manually overtyped, so I decided that checking the value of a new User-defined Cell, called IsDirty, was best, and then this value can be used to change the color of the text (or it could be the LineColor or FillForegnd) to make this value visible.
When Insert / Field is used in Visio, it creates a Text Fields section which can hold the reference to the inserted field.
If the text is manually overtyped, then the rows in the Text Fields section get deleted.
So, I wanted to highlight when this has happened so it can be handled in code.
First, I added a User.IsDirty row with the formula:
This returns False when the Fields.Value cell exists, returns True if it does not. Unfortunately, the User.IsDirty formula is automatically reset to ISERR(REF()) when the text is overtyped because the cell that it referred to is now deleted.
So, the next issue is to display this change in the UI, so I edited the Character.Color formula to change from Black to Red if IsDirty = True:
Now, I just needed to reset the User.IsDirty formula, so it will work again. Fortunately, the TheText cell in the Events section can react to a change in the text, so the following formula will re-instate the formula in the User.IsDirty cell:
This is possible because the Fields.Value is text in the above formula, so it will not get replaced with REF() in the SETF(…) formula.
So, I manually insert the Name Shape Data row back into the text, the color will automatically change back to Black.
Of course, the text field code be updated with some code, as follows, using the CALLTHIS(…) function:
The VBA sub-function ensures that the whole body of text is replaced with an inserted field:
Public Sub InsertField(ByVal shp As Visio.Shape, ByVal cellName As String)
Dim UndoScopeID1 As Long
UndoScopeID1 = Application.BeginUndoScope("Set Text Field")
Dim vsoChars As Visio.Characters
Set vsoChars = shp.Characters
vsoChars.Begin = 0
vsoChars.End = Len(shp.Characters)
vsoChars.AddCustomFieldU cellName, visFmtNumGenNoUnits
Application.EndUndoScope UndoScopeID1, True
Note that this solution only works for a single block of text, and not for large amounts of text where there are multiple inserted fields.
I recently had to revise my understanding of the POINTALONGPATH(…) function in Visio because I was getting a #REF! error in some cases. My particular scenario requires a line with a number of vertices that are initially all in a straight line but can be moved by dragging controls around that each vertex is bound…
I was recently looking into custom color themes for corporate branding in desktop Microsoft Visio and became re-aware how different Visio still is from the rest of the Microsoft Office applications. A Visio page or document does not need to have any theme applied, but the documents of the other Office applications always have a…
I have been a Visio user/developer since the mid-1990’s and seen the word “callout” used as part of the name of many master shapes in Visio. The images below show five ways that the term “callout” has been applied to the name of Visio master shapes. Generally, each evolution has been an advance on the…
Data Graphics in Visio Plan 2 and Visio Professional is great, but it only enables us to use them with 2D shapes in Visio, i.e. not on connectors. So, what if you want to change the line colour of the connectors between the 2D shapes because of the data flowing between them? Well, it is…
Visio shapes get their smartness from the formulas that are entered into the ShapeSheet, but editing these formulas can be extremely tricky and prone to error because of the lack of a modern programmer’s interface. Formulas can be quite long (up to 64k characters) but even medium size ones like the one in User.GetWorkdays cell…
I was recently asked if a second function header bar can be added to the swimlanes in the cross-functional flowchart templates in Visio. Some swimlanes can get quite wide, so it can be useful to have a duplicate function header shape on the far-side too. It is quite simple to duplicate the existing function header…