Visio Guy

Visio Discussions => Programming & Code => Topic started by: alexis-the-man on June 02, 2017, 03:38:06 PM

Title: Changing the Line color of a shape in Visio 2013?
Post by: alexis-the-man on June 02, 2017, 03:38:06 PM
This might be a dumb question, but I'm new to VBA and have been searching a solution for the past 2 hours.

I'm trying to change the color of a shape that acts as a connector, but i cant seem to get it to work.

This is the code I have now


    Dim con1 As Visio.Shape
   
    switch1.AutoConnect switch2, visAutoConnectDirNone, con1

    con1.CellsSRC(visSectionObject, visRowLine, visLineWeight).FormulaU = "1.5 pt"
    con1.CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(RGB(0,112,192))"

   
I get an error on the last line.  I've tried the last line with and without the themeguard part, and before the connector part.
Title: Re: Changing the Line color of a shape in Visio 2013?
Post by: wapperdude on June 02, 2017, 04:50:55 PM
You can use the macro recorder to get correct syntax.

Wapperdude
Title: Re: Changing the Line color of a shape in Visio 2013?
Post by: alexis-the-man on June 02, 2017, 05:11:22 PM
I did use a macro recorder.  Thats how I got what I have now.

The macrorecorder have me this,

Application.ActiveWindow.Page.Shapes.ItemFromID(1292).CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(RGB(0,112,192))"

So I replaced the index part with the name of the object, but it wont compile saying "Object Variable or with Object not set"
Title: Re: Changing the Line color of a shape in Visio 2013?
Post by: Yacine on June 02, 2017, 05:58:40 PM
1. Check your object. Before running the assignment, try debug.print con1.ID
2. If step 1 successful, then check Correct syntax
con1.CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "THEMEGUARD(RGB(0,112,192))"
Title: Re: Changing the Line color of a shape in Visio 2013?
Post by: wapperdude on June 02, 2017, 06:30:23 PM
I suspect Yacine's 1st test fails... now that you've indicated the error.  It's not a syntax error.

Not sure what switch1.AutoConnect switch2, visAutoConnectDirNone, con1 does, but the error indicates you've not assigned a shape to con1

Typically, the syntax would be:  set con1 =  some shape,  where the shape is specified by id, or selection.  Well, at least in V2007, V2013 may have a more context specific syntax.

Wapperdude
Title: Re: Changing the Line color of a shape in Visio 2013?
Post by: wapperdude on June 02, 2017, 10:26:35 PM
Turns out that you do have to set con1, and the code line I questioned is new to V2013.  See attached sample code.  In the example, your con1 = vsoConnectorShape.

BTW, if you haven't, you also need to set switch1 and switch2.

Here's the reference:  https://msdn.microsoft.com/en-us/library/office/ff765915.aspx (https://msdn.microsoft.com/en-us/library/office/ff765915.aspx)


Public Sub AutoConnect_Example()

    Dim vsoShape1 As Visio.Shape
    Dim vsoShape2 As Visio.Shape
    Dim vsoConnectorShape As Visio.Shape

    Set vsoShape1 = Visio.ActivePage.Shapes("Decision")
    Set vsoShape2 = Visio.ActivePage.Shapes("Process")
    Set vsoConnectorShape = Visio.ActivePage.Shapes("Dynamic connector")

    vsoShape1.AutoConnect vsoShape2, visAutoConnectDirRight, vsoConnectorShape

End Sub


Wapperdude