會傳回代表 ShapeSheet 儲存格的 Cell 物件。 唯讀。
語法
表情。儲存格 (localeSpecificCellName)
expression 一個用於表示 Shape 物件的變數。
參數
| 名稱 | 必要/選用 | 資料類型 | 描述 |
|---|---|---|---|
| localeSpecificCellName | 必要 | 字串 | ShapeSheet 儲存格的名稱。 |
傳回值
儲存格
註解
若「somestring」未命名實體儲存格 ( ) 則會觸發「檔案意外結束」例外。 使用 CellExists 屬性來判斷是否存在名為「somestring」的儲存格。
圖形的 [使用者自訂儲存格] 和 [圖形資料] 區段中的儲存格,屬於已由使用者或程式指派名稱的列。 使用 Cells 屬性來存取命名列中的儲存格。
例如,如果 "Row_1" 是圖形的 [使用者自訂儲存格] 區段中列的名稱,您可以使用這個陳述式來存取這個列中的第一個儲存格 (也就是資料欄零中存放列名稱的儲存格):
vsoCell = vsoShape.Cells("User.Row_1")
請使用此語句進入Row_1的提示格:
vsoCell = vsoShape.Cells("User.Row_1.Prompt")
接下來,假設 Row_1 是位於 [圖形資料] 區段,而不是 [使用者自訂儲存格] 區段。 使用此語句 (第零欄的儲存格中,存取該列的第一個儲存格,該格包含列名) :
vsoCell = vsoShape.Cells("Prop.Row_1")
使用此語句來存取該列中的其他儲存格:
vsoCell = vsoShape.Cells("Prop.Row_1.xxx")
其中 xxx 是下列其中一個儲存格:Label、Prompt、SortKey、Type、Format、Invisible 或 Ask。
注意事項
從 Microsoft Visio 2000 開始,你可以同時使用本地名稱和通用名稱來指稱 Visio 的圖形、主圖、文件、頁面、列、附加元件、儲存格、超連結、樣式、字型、主捷徑、UI 物件和圖層。 例如,當使用者命名一個形狀時,該使用者是在指定一個本地名稱。 從 Microsoft Office Visio 2003 開始,ShapeSheet 試算表僅在儲存格公式與值中顯示通用名稱。 (在早期版本中,通用名稱在使用者介面中無法顯示。)
身為開發人員,如果您不希望每次將方案本土化時就要變更名稱,可以在程式中使用通用名稱。 使用 Cells 屬性,透過當地 cell 名稱取得 Cell 物件。 使用 CellsU 屬性,利用 Cell 的通用名稱取得 Cell 物件。
範例
下列的 Microsoft Visual Basic for Applications (VBA) 巨集會示範如何使用 Cells 屬性,藉由特定 ShapeSheet 儲存格的名稱來取得該儲存格。 它會在頁面上繪製矩形,然後將圖形的線條變更為弧線來彎曲矩形的線條。 可以將矩形每個側邊的 ShapeSheet 列類型從 LineTo 變更為 ArcTo,然後變更其中每個列的 X 和 Y 儲存格的值來完成這項作業。
Public Sub Cells_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 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 and add a row to the scratch section.
vsoShape.AddSection visSectionScratch
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
End Sub
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。