vba 在 Visio 中按名称计算形状
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16559609/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Counting shapes by name in Visio
提问by Andrea Keil
I want to count different types of shapesin my diagram, and I can't seem to get that done. I think I have to code something for that. I use Visio 2007for that.
我想计算图表中不同类型的形状,但似乎无法完成。我想我必须为此编写一些代码。为此,我使用Visio 2007。
I have a flow chart with mostly process shapes that I want to distinguish by name. E.g "Type A", "Type B". And at the end, I want to have a list that tells me how often I used Type A and Type B. Counting by hand will be to error prone.
我有一个流程图,其中大部分是我想按名称区分的过程形状。例如“A 型”、“B 型”。最后,我想要一个列表,告诉我我使用 A 型和 B 型的频率。手动计数容易出错。
I already checked out the report/statistic function (I'm using it in German, so I'm afraid I can't tell you the exact menu name), where you can define a report function by yourself, although that one misses features for my needs. I managed to make a report for my shapes, but only when they all are selected. But when the user has to select them by hand, then he can count them as well right from the start... And you have to make 4-5 clicks in order to get that static report result.
我已经查看了报表/统计功能(我用的是德语,所以恐怕我不能告诉您确切的菜单名称),您可以在其中自己定义报表功能,尽管缺少功能为了我的需要。我设法为我的形状制作了一份报告,但前提是它们都被选中了。但是当用户必须手动选择它们时,他也可以从一开始就计算它们……您必须点击 4-5 次才能获得静态报告结果。
Another almost useful function I found was the layer method: Create a layer for the types I want to count, and then assign the shapes to that layer. But, again, this is too error prone. If the user misses a shape, the count will be wrong.
我发现的另一个几乎有用的功能是图层方法:为我想要计数的类型创建一个图层,然后将形状分配给该图层。但是,这又太容易出错了。如果用户错过了一个形状,则计数将是错误的。
So I think I will need to code something with the VBA. Additionally, I'd like to have a text field next to my diagramwhere the resulting counts for all types are always displayed. So that you see when you add a shape of Type A that the count goes up by one.
所以我想我需要用 VBA 编写一些代码。此外,我想在我的图表旁边有一个文本字段,其中始终显示所有类型的结果计数。这样您就可以看到,当您添加 A 型形状时,计数会增加 1。
Could anyone help me on this?
有人可以帮我吗?
回答by
try:
尝试:
Option Explicit
Dim myShape As Shape
Sub ShapesDetails()
Call DeleteShapes(True)
ActiveSheet.Shapes.AddShape(msoShapeRectangle, 139.5, 81.75, 72, 72).Select
Selection.Name = "Rectangle"
ActiveSheet.Shapes.AddShape(msoShapeSmileyFace, 252.75, 71.25, 72, 72).Select
Selection.Name = "Smiley Face"
Application.CutCopyMode = False
Call ShapeDetails(True)
End Sub
Sub ShapeDetails(x As Boolean)
For Each myShape In ActiveSheet.Shapes
MsgBox "Shape name: " & myShape.Name & vbTab & " Shape type: " & myShape.Type
Next
End Sub
Sub DeleteShapes(x As Boolean)
For Each myShape In ActiveSheet.Shapes
myShape.Delete
Next
End Sub
回答by james cooper
Use Data= reports = advanced to configure a report to count objects with your custom shape Property (e.g. 'MIO') && exists. (Or another field, many to choose from). I set all the boxes i wanted to count to have property 'MIO'=TRUE, and then chose to display property Displayed Text. It takes some fiddling around in the Subtotals dialog and options in the next window to get the count looking nice. Leave COUNT unticked, and in the options dialog enable 'show all values' and tick 'exclude duplicate rows from group'.
使用 Data=reports=advanced 配置报告以使用自定义形状属性(例如“MIO”)&存在来计算对象。(或其他领域,有很多可供选择)。我将所有要计数的框设置为属性 'MIO'=TRUE,然后选择显示属性 Displayed Text。需要在“小计”对话框和下一个窗口中的选项中进行一些摆弄,才能使计数看起来不错。不勾选 COUNT,并在选项对话框中启用“显示所有值”并勾选“从组中排除重复行”。
Outputs as XML Excel Viso object. I know for the visio object, to update report, right click on it =Run report.
输出为 XML Excel Viso 对象。我知道 visio 对象,要更新报告,右键单击它=运行报告。
HTH
HTH