Change milestone shape properties with VBA

Started by EndlessIdeas, April 12, 2014, 09:16:55 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

EndlessIdeas

I am creating a Viso timeline diagram programmatically from an Access database using VBA code.  I can easily drop a timeline into the page, place a line milestone on the timeline, enter text into the Milestone Description  via the Prop.visName cell, enter a date for the Milestone Date via the User.visMilestoneDate, and change the date format via the User.visMask.  I can even change the angle of the call-out line via two other cell entries.

I then want to orient the milestone description and date to a new angle.  However, I cannot figure out how to find or address the actual shape elements containing these two pieces of information.  When I move to the actual Visio diagram I can select the Milestone Description and Milestone Date shapes and manually change the angle by entering a value in the user.visTLAngle cell via "Show ShapeSheet".   It appears that the description and date information are contained in (sub?) shapes (or children or ???) of the selected shape.

Programmatically, how do I find these two sub-shapes and adequately identify them so I can change the angle values in the user.visTLAngle cell?  What I would expect, in order to change the angles to 45 degrees, is something along the following lines:

visShape.CellsU("User.visTLAngle").FormulaU = """45"""
                        or
Application.ActiveWindow.Page.Shapes.ItemFromID(<ID>).CellsU(("User.visTLAngle").FormulaU = """45""".

I think I understand how to change the value of the cells, I just cannot figure out how to find the correct subshape (or whatever it is called) within a shape and, then, how to address it.

Thank you, in advance, for your assistance.


EndlessIdeas

Well, after over 20 hours of research and trial and error, I finally came up with a solution that works.  I am tenacious (OK, obsessive) when it comes to problem solving.   Here it is:

Public Function ChangeSubShapeAngle(ByVal shp As Visio.Shape, strShapeType As String, strAngle As String) As Variant
'Change the angle of a shape within a shape.
On Error GoTo errHandler
    Dim shpSub              As Visio.Shape
   
    For Each shpSub In shp.Shapes
        If shpSub.CellsSRC(visSectionUser, 0, visUserValue).FormulaU = strShapeType Then
            shpSub.CellsU("User.visTLAngle").FormulaU = """" & strAngle & """"
        End If
    Next
   
exitHere:
    Exit Function
errHandler:
    MsgBox Err.Description, vbCritical, "ChangeSubShapeAngle"
    Resume exitHere
End Function

The typical call to this function looks like this:

        Call ChangeSubShapeAngle(shpVsoTLMilestone, "18", "43 deg")

The strShapeType for the milestone text is "18" and for the Date field is "19".  The strAngle must be provided in the form of "X deg".  It all works well and I am now able to change other parameters for these two fields.

I only began creating a Visio diagram with VBA 10 days ago and have been totally on my own.  If there was a more straight forward approach to this, I would still like to know.

Thanks.