LineColor not changing when set

J

JB

I set my LineColor as follows:

Set objcell2 = vsoShape2.Cells("LineColor")objcell2.Formula = 3

If I view my line color property from within the Visio application it shows
it is set to 3 but the color on the diagram does not reflect line color 3.

Does anyone know why this is happening?

Thanks

JB
 
C

Chris Roth [ Visio MVP ]

My guess is that your shape is a group. Sub-shapes in the group do not
reference the group's linecolor settings (or any other formatting
attributes) And groups usually do not contain any geometry sections,
although they may.

When you click the line color button on the toolbar, Visio steps through all
selected shapes and their sub-shapes and sets the LineColor cell for all
shapes that don't have any protection or guarding. What you can do is set
all of your sub-shapes to point to the group's setting:

subShape.LineColor = Guard(Sheet.5!LineColor)

Sheet.5 is the ID of your group (goto Format > Special > ID: field) Guard
stops future toolbar button clicks from blowing away your intelligent
formulas.

--

Hope this helps,

Chris Roth
Visio MVP
 
J

JB

Thanks for your response.

I want to change the color of my Line Milestones that sit on a timeline. I
apologize but I am not very familiar with Visio and do not fully understand
your comments below. Am I supposed to set the color per Line Milestone?
 
J

JB

I should mention that I would like a diffent color per milestone. So
basically, in my code, I am looping through a recordset and droping
miletones onto the page..it is at this time that I want to set the milestone
line color. Thanks for you help
 
C

Chris Roth [ Visio MVP ]

Here's some sample code for you.

Test runs FormatLines, which is the core smarts. Select a milestone shape
and run Test. FormatLines sets formulas in the sub-shapes inside the
milestone shape, such that you only need to change the LineColor of ths
shape.

A better option is to edit the master (in the document stencil of the
document you are editing). Then you only have to run FormatLines once for
each master that gets added to your drawing, all instances of that master
will be "smart" thereafter.

Your document has a MastersAdded event. When you first drop a new master
into a document, a copy of that master gets put in the document's
inner-stencil. See menu: File > Shapes > Show Document Stencil. Per
automation: Doc.Masters...


Sub Test()
Dim shp As Visio.Shape
Set shp = Visio.ActiveWindow.Selection(1)
FormatLines shp, 3
End Sub

Sub FormatLines(shpGrp As Visio.Shape, lineColor As Integer)

Dim shpSub As Visio.Shape
Dim sGrpName As String
Dim sColFormula As String

sGrpName = shpGrp.NameID 'This will be something like 'Sheet.10'

shpGrp.Cells("LineColor").ResultIU = lineColor

For Each shpSub In shpGrp.Shapes
' The text sub shapes don't need to have the smart formula:
If shpSub.Text = vbNullString Then
' Okay, this is a normal sub-shape - set a formula to
' refer to the group's linecolor. An example formula:
'
' GUARD( Sheet.5!LineColor )
'
sColFormula = "GUARD(PAR!LineColor)"
sColFormula = Replace(sColFormula, "PAR", sGrpName)
shpSub.Cells("LineColor").Formula = sColFormula
End If
Next shpSub

End Sub

Sub EditMaster(shpGrp As Visio.Shape, lineColor As Integer)

If shpGrp.Master Is Nothing Then Exit Sub

Dim shpInside As Visio.Shape
Dim mst As Visio.Master, mstCopy As Visio.Master

Set mst = shpGrp.Master
Set mstCopy = mst.Open
Set shpInside = mstCopy.Shapes(1)
Call FormatLines(shpInside, 3)
mstCopy.Close
Set mst = Nothing
Set mstCopy = Nothing

End Sub


--

Hope this helps,

Chris Roth
Visio MVP
 
J

JB

Thanks a bunch Chris!


Chris Roth said:
Here's some sample code for you.

Test runs FormatLines, which is the core smarts. Select a milestone shape
and run Test. FormatLines sets formulas in the sub-shapes inside the
milestone shape, such that you only need to change the LineColor of ths
shape.

A better option is to edit the master (in the document stencil of the
document you are editing). Then you only have to run FormatLines once for
each master that gets added to your drawing, all instances of that master
will be "smart" thereafter.

Your document has a MastersAdded event. When you first drop a new master
into a document, a copy of that master gets put in the document's
inner-stencil. See menu: File > Shapes > Show Document Stencil. Per
automation: Doc.Masters...


Sub Test()
Dim shp As Visio.Shape
Set shp = Visio.ActiveWindow.Selection(1)
FormatLines shp, 3
End Sub

Sub FormatLines(shpGrp As Visio.Shape, lineColor As Integer)

Dim shpSub As Visio.Shape
Dim sGrpName As String
Dim sColFormula As String

sGrpName = shpGrp.NameID 'This will be something like 'Sheet.10'

shpGrp.Cells("LineColor").ResultIU = lineColor

For Each shpSub In shpGrp.Shapes
' The text sub shapes don't need to have the smart formula:
If shpSub.Text = vbNullString Then
' Okay, this is a normal sub-shape - set a formula to
' refer to the group's linecolor. An example formula:
'
' GUARD( Sheet.5!LineColor )
'
sColFormula = "GUARD(PAR!LineColor)"
sColFormula = Replace(sColFormula, "PAR", sGrpName)
shpSub.Cells("LineColor").Formula = sColFormula
End If
Next shpSub

End Sub

Sub EditMaster(shpGrp As Visio.Shape, lineColor As Integer)

If shpGrp.Master Is Nothing Then Exit Sub

Dim shpInside As Visio.Shape
Dim mst As Visio.Master, mstCopy As Visio.Master

Set mst = shpGrp.Master
Set mstCopy = mst.Open
Set shpInside = mstCopy.Shapes(1)
Call FormatLines(shpInside, 3)
mstCopy.Close
Set mst = Nothing
Set mstCopy = Nothing

End Sub


--

Hope this helps,

Chris Roth
Visio MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top