ActiveSheet是一个Excel属性。我想你在找
ActivePage
,这是一个Visio等效。因此,要修复上面的代码,您可以使用:
For Each shp In ActivePage.Shapes
count = count + 1
Debug.Print count
Next
</code>
但是,如果您只是在页面的形状计数之后,那么您可以改为:
Debug.Print ActivePage.Shapes.Count
</code>
我可以推荐一些可能也有帮助的链接:
http://visualsignals.typepad.co.uk/vislog/2007/10/just-for-starte.html
http://visualsignals.typepad.co.uk/vislog/2007/11/looping-through.html
用于visio的vba编程
作为替代方法,您可能也对Visio的内置报告工具感兴趣:
问题的第二部分(检查数据字段)我假设你在谈论读取形状数据。如果是这种情况,您首先要检查是否存在名为“ID”的行,如果存在,则读取该值。所以这样的事情可能会让你前进:
Public Sub TestGetCellValues()
GetShapesCellValues ActivePage, “Prop.ID”
End Sub
Public Sub GetShapesCellValues(targetPage As Visio.Page, targetCellName As String)
Dim shp As Visio.Shape
If Not targetPage Is Nothing Then
For Each shp In targetPage.Shapes
If shp.CellExistsU(targetCellName, 0) = True Then
Debug.Print shp.NameID & “!”
& targetCellName & “ = “
& shp.CellsU(targetCellName).ResultIU
End If
Next shp
End If
End Sub
</code>
…可能输出这样的东西(给定相关的形状):
Sheet.2!Prop.ID = 3
</code>