共用方式為


Shape.CellsSRC 屬性 (Visio)

會傳回 Cell 物件,此物件代表根據區段、列和資料欄索引所識別的 ShapeSheet 儲存格。 唯讀。

語法

expressionCellsSRC( _Section_ , _Row_ , _Column_ )

expression 一個用於表示 Shape 物件的變數。

參數

名稱 必要/選用 資料類型 描述
Section 必要 整數 儲存格的區段索引。
Row 必要 整數 儲存格的列索引。
必要 整數 儲存格的資料欄索引。

傳回值

儲存格

註解

若要藉由圖形的區段、列和資料欄索引存取任何圖形,可以使用 CellsSRC 屬性。 區段、列與欄索引的常數分別由 Visio 類型庫宣告為 VisSectionIndicesVisRowIndicesVisCellInindex 的成員。

如果 section、row 和 column 的索引值無法識別實際儲存格,根據 section 不同, CellsSRC 屬性可能會觸發例外。 不過,即使不會觸發例外,在傳回的物件上所觸發的後續方法也會失敗。 您可以使用 CellsSRCExists 屬性來判斷具有特定索引值的儲存格是否存在。

CellsSRC 屬性通常會用來重覆區段或列中的儲存格。 若要擷取單一的儲存格,可以使用 Cells 屬性並指定儲存格名稱。 例如:

Set vsoCell = Cells("PinX")

如果 Visual Studio 解決方案包括 Microsoft.Office.Interop.Visio 參照,這個屬性會對應至下列類型:

  • Microsoft.Office.Interop.Visio.IVShape.get_CellsSRC

範例

以下Microsoft Visual Basic for Applications (VBA) 巨集 展示了如何使用 CellsSRC 屬性,依據 ShapeSheet 的截面、列和欄索引來設定特定 ShapeSheet 儲存格。 它會在頁面上繪製矩形,然後將圖形的線條變更為弧線來彎曲矩形的線條。 巨集接著在第一個矩形的彎曲線條內繪製一個內長方形。

 
Public Sub CellsSRC_Example() 
  
    Dim vsoPage As Visio.Page  
    Dim vsoShape As Visio.Shape  
    Dim vsoCell As Visio.Cell  
    Dim strBowCell As String 
    Dim strBowFormula As String 
    Dim intIndex As Integer 
    Dim intCounter As Integer 
 
    'Set the value of the strBowCell string.  
    strBowCell = "Scratch.X1"  
 
    'Set the value of the strBowFormula string.  
    strBowFormula = "=Min(Width, Height) / 5"  
 
    Set vsoPage = ActivePage  
 
    'If there isn't an active page, set vsoPage 
    'to the first page of the active document. 
    If vsoPage Is Nothing Then 
        Set vsoPage = ActiveDocument.Pages(1)  
    End If   
 
    'Draw a rectangle on the active page. 
    Set vsoShape = vsoPage.DrawRectangle(1, 5, 5, 1)  
 
    'Add a scratch section to the shape's ShapeSheet  
    vsoShape.AddSection visSectionScratch  
 
    'Add a row to the scratch section.  
    vsoShape.AddRow visSectionScratch, visRowScratch, 0  
 
    'Set vsoCell to the Scratch.X1 cell and set its formula. 
    Set vsoCell = vsoShape.Cells(strBowCell)  
    vsoCell.Formula = strBowFormula  
 
    'Bow in or curve the rectangle's lines by changing 
    'each row type from LineTo to ArcTo and entering the bow value. 
    For intCounter = 1 To 4  
        vsoShape.RowType(visSectionFirstComponent, visRowVertex + intCounter) = visTagArcTo  
        Set vsoCell = vsoShape.CellsSRC(visSectionFirstComponent, visRowVertex + intCounter, 2)  
        vsoCell.Formula = "-" & strBowCell  
    Next intCounter  
 
    'Create an inner rectangle. 
    'Set the section index for the inner rectangle's Geometry section.  
    intIndex = visSectionFirstComponent + 1  
 
    'Add an inner rectangle Geometry section.  
    vsoShape.AddSection intIndex  
 
    'Add the first 2 rows to the section.  
    vsoShape.AddRow intIndex, visRowComponent, visTagComponent  
    vsoShape.AddRow intIndex, visRowVertex, visTagMoveTo 
  
    'Add 4 LineTo rows to the section 
    For intCounter = 1 To 4  
        vsoShape.AddRow intIndex, visRowLast, visTagLineTo  
    Next intCounter  
 
    'Set the inner rectangle start point cell formulas. 
    Set vsoCell = vsoShape.CellsSRC(intIndex, 1, 0)  
    vsoCell.Formula = "Width * 0 + " & strBowCell  
    Set vsoCell = vsoShape.CellsSRC(intIndex, 1, 1)  
    vsoCell.Formula = "Height * 0 + " & strBowCell  
 
    'Draw the inner rectangle bottom line. 
    Set vsoCell = vsoShape.CellsSRC(intIndex, 2, 0)  
    vsoCell.Formula = "Width * 1 - " & strBowCell  
    Set vsoCell = vsoShape.CellsSRC(intIndex, 2, 1)  
    vsoCell.Formula = "Height * 0 + " & strBowCell 
  
    'Draw the inner rectangle right side line. 
    Set vsoCell = vsoShape.CellsSRC(intIndex, 3, 0)  
    vsoCell.Formula = "Width * 1 - " & strBowCell  
    Set vsoCell = vsoShape.CellsSRC(intIndex, 3, 1)  
    vsoCell.Formula = "Height * 1 - " & strBowCell  
 
    'Draw the inner rectangle top line. 
    Set vsoCell = vsoShape.CellsSRC(intIndex, 4, 0)  
    vsoCell.Formula = "Width * 0 + " & strBowCell  
    Set vsoCell = vsoShape.CellsSRC(intIndex, 4, 1)  
    vsoCell.Formula = "Height * 1 - " & strBowCell  
 
    'Draw the inner rectangle left side line. 
    Set vsoCell = vsoShape.CellsSRC(intIndex, 5, 0)  
    vsoCell.Formula = "Geometry2.X1"  
    Set vsoCell = vsoShape.CellsSRC(intIndex, 5, 1)  
    vsoCell.Formula = "Geometry2.Y1"  
 
End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應