2009-02-03 41 views

Trả lời

6

Để có được tùy chỉnh hình thông tin từ một hình dạng 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 

Tất cả các chức năng này thực hiện là sử dụng tài sản cellsu trên hình dạng để có được những tế bào ShapeSheet tài sản tùy chỉnh theo tên ...

Nếu bạn là một người đam mê về việc sử dụng lỗi khi tiếp tục, bạn có thể kiểm tra xem ô có tồn tại hay không bằng cách kiểm tra xem ô có tồn tại hay không trước tiên:

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

'CellExistsU' trả về một số nguyên theo [tài liệu] (https://msdn.microsoft.com/en-us/vba/visio-vba/articles/shape-cellexistsu- tài sản-visio). Bạn có chắc chắn nó có thể được sử dụng như một boolean (0 cho false, nonzero cho đúng)? – jpmc26

+0

vâng tôi chắc chắn, tài liệu không thực sự nói những gì được trả lại nhưng tôi đã sử dụng nó nhiều lần như một boolean. –

3

Tìm thấy tại http://visio.mvps.org/VBA.htm (Custom Thuộc tính)

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 
Các vấn đề liên quan