Hi Dave,
My worm-protection was freaking out and I didn't get to the newsgroups for
awhile...
My guess is that your error is coming from the hard-coded ids inside of the
ItemFromID() properties. Every Visio shape has a different ID, so you'll
have to parameterize the ids that you get in the macro-generated code.
Anyway, try this code (in a blank drawing) - it might help you to better see
how to structure everything:
----------
Sub Dave()
Dim shp1 As Visio.Shape, shp2 As Visio.Shape
'// Draw shape 1:
Set shp1 = Visio.ActivePage.DrawRectangle(1, 1, 3, 3)
shp1.CellsU("LineWeight").ResultIU = 0.25
shp1.Text = "One"
'// Draw shape 2:
Set shp2 = Visio.ActivePage.DrawRectangle(4, 1, 6, 3)
shp2.CellsU("LineWeight").ResultIU = 0.25
shp2.Text = "Two"
Call MsgBox("Here's two shapes on the page. Let's try the conditional
formatting:")
Call m_conditionalFormat(shp1, shp2)
Call MsgBox("Now turn shp1 green:")
shp1.CellsU("FillForegnd").FormulaForceU = "RGB(0,255,0)"
Call MsgBox("Now, try the conditional formatting again:")
Call m_conditionalFormat(shp1, shp2)
Call MsgBox("Cool!")
End Sub
Private Sub m_conditionalFormat(shp1 As Visio.Shape, shp2 As Visio.Shape)
'// If shp1 has a green fill:
If (shp1.CellsU("FillForegnd").ResultIU = 2) Or _
(shp1.CellsU("FillForegnd").ResultStr(visNoCast) = "RGB(0, 255, 0)")
Then ' note the spaces after the commas!
'// Do if green:
shp2.Cells("LineColor").FormulaForceU = "RGB(51,204,204)"
Else
'// Do if not green:
shp2.Cells("LineColor").FormulaForceU = "2"
End If
End Sub
----------
-----
--
Hope this helps,
Chris Roth
Visio MVP
Free Visio shapes:
http://www.visguy.com/category/shapes
Visio programming info:
http://www.visguy.com/category/programming/
Other Visio resources:
http://www.visguy.com/visio-links/
- Show quoted text -