简体   繁体   English

在 Visio 中更改形状颜色

[英]Changing Shape Color in Visio

Need some help!需要一些帮助!

I'm relatively knowledgeable when it comes to macros, VBA, scripts, etc., but Visio coding is an all new monster to me.我在宏、VBA、脚本等方面比较了解,但 Visio 编码对我来说是一个全新的怪物。

In short, I have a warehouse map layout with simple square shapes marking product locations, and I want to color-code the squares based on their Prop._VisDM_F2 data element.简而言之,我有一个仓库地图布局,带有简单的正方形形状标记产品位置,我想根据它们的Prop._VisDM_F2数据元素对正方形进行颜色编码。 My code so far seems to work, but only for the 1st shape in the group of squares, but sometimes the master shape consists of 1 square, sometimes 6, and everything in between.到目前为止,我的代码似乎有效,但仅适用于正方形组中的第一个形状,但有时主形状包含 1 个正方形,有时 6 个,以及介于两者之间的所有形状。

I've learned that the # in "Shapes( # )" selects which square gets changed, but I want them ALL to change.我了解到,在“形状(#)”选择#这方得到改变,但我想他们改变。 I've tried to get a count of how many individual shapes are in each master shape to use a variable integer as the # , but it didn't work.我试图计算每个主形状中有多少个单独的形状以使用可变整数作为# ,但它没有用。

Surely such a simple task can't really this complicated so I'm probably just missing something a step.当然,这样一个简单的任务不可能真的这么复杂,所以我可能只是错过了一步。 Any help would be greatly appreciated!任何帮助将不胜感激!

''' '''

Dim selectObj As Visio.Shape

For Each selectObj In ActiveWindow.Selection
If selectObj.CellExistsU("Prop._VisDM_F2", Visio.VisExistsFlags.visExistsAnywhere) Then
selectObj.Shapes(1).Cells("Fillforegnd").FormulaU = visWhite
End If
Next

End Sub

''' '''

Shapes can have sub-shapes which are accessed through the Shapes property as per your code (note that most Visio collections are 1 rather than 0 based).形状可以有子形状,这些子形状可以根据您的代码通过 Shapes 属性访问(请注意,大多数 Visio 集合都是基于 1 而不是基于 0)。

You can address the sub-shapes collection either by index or with a further for each.您可以通过索引或每个的进一步处理子形状集合。 So given that you may or may not know the depth of your sub-shapes you can recurse through them something like this:因此,考虑到您可能知道也可能不知道子形状的深度,您可以像这样递归它们:

Sub ApplyFillToAll()

Dim shp As Visio.Shape

For Each shp In ActiveWindow.Selection
    If shp.CellExistsU("Prop._VisDM_F2", Visio.VisExistsFlags.visExistsAnywhere) Then
        SetFill shp, "RGB(255,0,0)"
    End If
Next

End Sub

Public Sub SetFill(ByRef shpIn As Visio.Shape, fillFormula As String)

Dim shp As Visio.Shape

For Each shp In shpIn.Shapes
    shp.Cells("FillForegnd").FormulaU = fillFormula
    SetFill shp, fillFormula
Next

End Sub

Note that the formula that you're setting is a string and so is wrapped in double quotes, and the above will set all of the sub-shapes to red with the SetFill method calling itself to navigate down through the tree.请注意,您设置的公式是一个字符串,因此用双引号括起来,上面的代码会将所有子形状设置为红色,并通过调用自身的 SetFill 方法在树中向下导航。

I'll add a link to a very old post that you might also find useful:我将添加一个链接到一个非常旧的帖子,您可能也会发现它很有用:

https://visualsignals.typepad.co.uk/vislog/2007/11/looping-through.html https://visualsignals.typepad.co.uk/vislog/2007/11/looping-through.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM