返回另一个单元格的公式所依赖的 ShapeSheet 单元格数组。 此为只读属性。
语法
表达式。先例
表达 一个代表 Cell 对象的变量。
返回值
Cell ()
备注
Precedents 属性返回一个单元格数组,该数组导致父 Cell 对象在公式或值更改时重新计算其值。
示例
以下 Microsoft Visual Basic for Applications (VBA) 宏演示如何使用 Precedents 属性显示形状的“Scratch.X1”单元格所依赖的单元格列表。 该宏在活动页上绘制一个矩形,向矩形的 ShapeSheet 添加一个 Scratch 部分,然后在该部分的单元格中输入一个公式,该公式用于向内弯曲矩形的两侧,方法是将每个矩形的边更改为一个弧线。由于用于弯曲矩形边的公式取决于矩形的宽度和高度,因此包含公式 Scratch.X1 的单元格依赖于矩形形状的 Width 和 Height 单元格,因此这些单元格成为先例。
Public Sub Precedents_Example()
Dim acellPrecedentCells() As Visio.Cell
Dim vsoCell As Visio.Cell
Dim vsoShape As Visio.Shape
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"
'Draw a rectangle on the active page
Set vsoShape = ActivePage.DrawRectangle(1, 5, 5, 1)
'Add a scratch section and then
vsoShape.AddSection visSectionScratch
'Add a row to the scratch section
vsoShape.AddRow visSectionScratch, visRowScratch, 0
'Place the value of strBowFormula into Scratch.X1
'Set the Cell object to the Scratch.X1 and set formula
Set vsoCell = vsoShape.Cells(strBowCell)
'Set up the offset for the arc
vsoCell.Formula = strBowFormula
'Bow in or curve the original rectangle's lines by changing
'each row to an arc 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
'Get the array of precedent cells
acellPrecedentCells = vsoShape.Cells("Scratch.X1").Precedents
'List the cell names and their associated formula
For intCounter = LBound(acellPrecedentCells) To UBound(acellPrecedentCells)
Set vsoCell = acellPrecedentCells(intCounter)
Debug.Print vsoCell.Name & " has this formula: " & vsoCell.Formula
Next
End Sub
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。