Visio) (Style.Cells 屬性

會傳回代表 ShapeSheet 儲存格的 Cell 物件。 唯讀。

語法

運算式localeSpecificCellName (儲存格)

表達 代表 Style 物件的變數。

參數

名稱 必要/選用 資料類型 描述
localeSpecificCellName 必要 字串 ShapeSheet 儲存格的名稱。

傳回值

儲存格

註解

如果 「somestring」 未命名為實際儲存格,則 (「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 物件。 使用 CellsU 屬性可使用儲存格的通用名稱來取得 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 支援與意見反應