Visio Guy

Visio Discussions => Programming & Code => Topic started by: amax on January 18, 2016, 10:34:52 AM

Title: Change Text Value of all InformationFlow Shapes
Post by: amax on January 18, 2016, 10:34:52 AM
Hey guys,

I'm new to this Visio topic, also my VBA skills are not A+ level. However, what I want to do is to change in a information flow shape the "Text Field"-Value of all Information Flow and Information Flow Bidirectional and Information Flow without direction.
To change this value in a single information flow it is like this:
Application.ActiveWindow.Shape.CellsSRC(visSectionTextField, 0, visFieldCell).FormulaU = "Prop._VisDM_Prop_InformationObjects"

But how I can get only, but all three Information Flow types in a Shape? Ok, I know with a loop, but how to catch not an Application?

Best regards
Amax
Title: Re: Change Text Value of all InformationFlow Shapes
Post by: JohnGoldsmith on January 18, 2016, 03:32:43 PM
Hello Amax,


Which stencil and template is this from?  Also, are you trying to change on document or multiple ones?


Best regards


John
Title: Re: Change Text Value of all InformationFlow Shapes
Post by: amax on January 18, 2016, 04:16:08 PM
Hi John,

the used stecils are: InformationFlow, InformationFlowBidirectional, InformationflowNoDirection, Application-cp-s-Bo, Application-cp-s-Small, Application-cp-m-Bo, Application-cp-m-Small.
In the properties is the template information empty. As far as I know, this sheet is generated by a tool for drawing information flow diagrams.

I try to change one document, but use a external excel file to link the relevant information I want to change with the current one stored in the visio file.
Title: Re: Change Text Value of all InformationFlow Shapes
Post by: JohnGoldsmith on January 19, 2016, 10:12:19 AM
Hi,

I think you're describing Master names rather than a stencil, which is the document that contains a set of masters?  I'm not familiar with the shapes you're describing, but is sounds like editting the document master shapes manually might be a better choice.  Do you have a sample document that you could post so we know what we're dealing with?

Best regards

John
Title: Re: Change Text Value of all InformationFlow Shapes
Post by: amax on January 19, 2016, 01:50:05 PM
Hey John,

I'm sorry that I can't be specific enough. Attached the file.

regards
Title: Re: Change Text Value of all InformationFlow Shapes
Post by: JohnGoldsmith on January 19, 2016, 03:17:36 PM
Hi,

Thanks - that's helpful. 

So as I understand it you want to edit the text fields of three of the Information type connector shapes - is that right? 

I see that a number of the shapes have local formulas (ie they do not inherit this information from their respective masters) and I think my approach would be to reset inheritance so that you can then edit the master manually in one place, and have the changes reflected across all of the instance shapes.

Anyway, it's up to you obviously, so I've included both options in the code below:

Public Sub ResetPageInfoConns()
    Dim newFormula As String
   
    'uncomment this line to reset the field cell's inheritance to point at the master
    'newFormula = "="
                       
    'or uncomment this line to set the instance (if you must!):
    'newFormula = "Prop._VisDM_Prop_InformationObjects"
   
    Dim masterNames As Variant
    masterNames = Split("InformationFlow;InformationFlowBidirectional;InformationFlowNoDirection", ";", newFormula)
    Call ResetFields(ActivePage, masterNames, newFormula)
End Sub

Private Sub ResetFields(ByRef targetPage As Visio.Page, masterNames As Variant, newFormula As String)
Dim shp As Visio.Shape
If Not targetPage Is Nothing Then
    For Each shp In targetPage.Shapes
        If Not shp.Master Is Nothing Then
            Dim i As Long
            For i = 0 To UBound(masterNames)
                If shp.Master.Name = masterNames(i) Then
                    If shp.CellsSRCExists(visSectionTextField, 0, visFieldCell, VisExistsFlags.visExistsLocally) Then
                        Debug.Print shp.Master.Name, shp.NameID, "Found shape with field"
                       
                        'uncomment to set the cell
                        'shp.CellsSRC(visSectionTextField, 0, visFieldCell).FormulaU = newFormula
                    Else
                        Debug.Print shp.Master.Name, shp.NameID, "Found shape with no field"
                    End If
                End If
            Next i
        End If
    Next
End If
End Sub


Let me know how you get on.

Best regards

John
Title: Re: Change Text Value of all InformationFlow Shapes
Post by: amax on January 20, 2016, 08:58:09 AM
Great, it works! Thank you!
Title: Re: Change Text Value of all InformationFlow Shapes
Post by: JohnGoldsmith on January 20, 2016, 09:59:43 AM
Great.  Glad it worked for you.

Best regards

John
Browser ID: smf (is_webkit)
Templates: 1: Printpage (default).
Sub templates: 4: init, print_above, main, print_below.
Language files: 1: index+Modifications.english (default).
Style sheets: 0: .
Hooks called: 62 (show)
Files included: 25 - 925KB. (show)
Memory used: 762KB.
Tokens: post-login.
Cache hits: 7: 0.00096s for 22,301 bytes (show)
Cache misses: 1: (show)
Queries used: 9.

[Show Queries]