【问题标题】:How do I retrieve Visio custom shape information with VBA如何使用 VBA 检索 Visio 自定义形状信息
【发布时间】:2010-10-05 04:16:34
【问题描述】:

使用 VBA,我如何从 Visio 2003 图表中检索自定义形状信息。

【问题讨论】:

    标签: vba ms-office visio office-2003


    【解决方案1】:

    从 Visio 形状获取自定义形状信息:

    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 单元格...

    如果你是一个坚持使用 on error resume next 的人,你可以通过首先检查单元格是否存在来检查单元格是否存在:

    if TheShape.CellExistsU( "Prop." & ThePropertyName , 0 ) then
    GetCustomPropertyValue = TheShape.CellsU("Prop." & THePropertyName).ResultStr(VisNone)
    

    【讨论】:

    • CellExistsU 根据the documentation 返回一个整数。你确定它可以用作布尔值(0 表示假,非零表示真)?
    • 是的,我敢肯定,文档并没有真正说明返回了什么,但我已经多次将它用作布尔值。
    【解决方案2】:

    http://visio.mvps.org/VBA.htm(自定义属性)找到这个

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多