Changing the Line color of a shape in Visio 2013?

Started by alexis-the-man, June 02, 2017, 03:38:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

alexis-the-man

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.

wapperdude

You can use the macro recorder to get correct syntax.

Wapperdude
Visio 2019 Pro

alexis-the-man

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"

Yacine

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))"
Yacine

wapperdude

#4
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
Visio 2019 Pro

wapperdude

#5
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


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
Visio 2019 Pro