如何使用VBA检索Visio自定义形状信息
使用VBA,如何从Visio 2003图表中检索自定义形状信息。要从Visio形状中获取自定义形状信息,请执行以下操作:如何使用VBA检索Visio自定义形状信息,vba,ms-office,visio,office-2003,Vba,Ms Office,Visio,Office 2003,使用VBA,如何从Visio 2003图表中检索自定义形状信息。要从Visio形状中获取自定义形状信息,请执行以下操作: Function GetCustomPropertyValue(TheShape As Visio.Shape, ThePropertyName As String) As String On Error Resume Next GetCustomPropertyValue = TheShape.CellsU("Prop." & TheProperty
Function GetCustomPropertyValue(TheShape As Visio.Shape, ThePropertyName As String) As String
On Error Resume Next
GetCustomPropertyValue = TheShape.CellsU("Prop." & ThePropertyName).ResultStr(visNone)
End Function
此函数所做的只是使用形状上的cellsu属性按名称获取自定义属性ShapeSheet cell
如果您坚持使用on error resume next,您可以通过首先检查单元格是否存在来检查单元格是否存在:
if TheShape.CellExistsU( "Prop." & ThePropertyName , 0 ) then
GetCustomPropertyValue = TheShape.CellsU("Prop." & THePropertyName).ResultStr(VisNone)
在(自定义属性)处找到此
CellExistsU
根据返回一个整数。您确定它可以用作布尔值(0表示false,非零表示true)吗?是的,我确定,文档中没有真正说明返回的内容,但我已经多次将其用作布尔值。
Public Sub CustomProp()
Dim shpObj As Visio.Shape, celObj As Visio.Cell
Dim i As Integer, j As Integer, ShpNo As Integer
Dim LabelName As String, PromptName As String, ValName As String, Tabchr As String
Open "C:\CustomProp.txt" For Output Shared As #1
Tabchr = Chr(9)
For ShpNo = 1 To Visio.ActivePage.Shapes.Count
Set shpObj = Visio.ActivePage.Shapes(ShpNo)
nRows = shpObj.RowCount(Visio.visSectionProp)
For i = 0 To nRows - 1
Set celObj = shpObj.CellsSRC(Visio.visSectionProp, i, 0)
ValName = celObj.ResultStr(Visio.visNone)
Set celObj = shpObj.CellsSRC(Visio.visSectionProp, i, 1)
PromptName = celObj.ResultStr(Visio.visNone)
Set celObj = shpObj.CellsSRC(Visio.visSectionProp, i, 2)
LabelName = celObj.ResultStr(Visio.visNone)
Debug.Print shpObj.Name, LabelName, PromptName, ValName
Print #1, shpObj.Name; Tabchr; LabelName; Tabchr; PromptName; Tabchr; ValName
Next i
Next ShpNo
Close #1
End Sub