Author Topic: Changing the Line color of a shape in Visio 2013?  (Read 5397 times)

0 Members and 1 Guest are viewing this topic.

alexis-the-man

  • Newbie
  • *
  • Posts: 2
Changing the Line color of a shape in Visio 2013?
« on: June 02, 2017, 10:38:06 AM »
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4882
  • Ideas Visio-lized into solutions
Re: Changing the Line color of a shape in Visio 2013?
« Reply #1 on: June 02, 2017, 11:50:55 AM »
You can use the macro recorder to get correct syntax.

Wapperdude
Visio 2019 Pro

alexis-the-man

  • Newbie
  • *
  • Posts: 2
Re: Changing the Line color of a shape in Visio 2013?
« Reply #2 on: June 02, 2017, 12: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"

Yacine

  • Hero Member
  • *****
  • Posts: 3236
Re: Changing the Line color of a shape in Visio 2013?
« Reply #3 on: June 02, 2017, 12: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))"
Yacine

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4882
  • Ideas Visio-lized into solutions
Re: Changing the Line color of a shape in Visio 2013?
« Reply #4 on: June 02, 2017, 01: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
« Last Edit: June 02, 2017, 04:14:25 PM by wapperdude »
Visio 2019 Pro

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4882
  • Ideas Visio-lized into solutions
Re: Changing the Line color of a shape in Visio 2013?
« Reply #5 on: June 02, 2017, 05: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

Code
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
« Last Edit: June 02, 2017, 05:45:21 PM by wapperdude »
Visio 2019 Pro