返回另一个单元格的公式所依赖的 ShapeSheet 单元格数组。 此为只读属性。
语法
表达式。Precedents
表达式 表示 Cell 对象的变量。
返回值
单元格 ()
备注
Precedents 属性返回一个单元格数组,这些单元格的公式或值发生更改时会导致父 Cell 对象重新计算其值。
示例
以下 VBA) 宏Visual Basic for Applications (Microsoft显示如何使用 Precedents 属性显示形状的“Scratch.X1”单元格所依赖的单元格列表。 该宏在活动页上绘制一个矩形,将暂存部分添加到矩形的 ShapeSheet,然后在该部分的单元格中输入一个公式,该公式用于通过将矩形的每边都更改为弧线来使矩形的边向内弯曲。由于用于弯曲矩形边的公式取决于矩形的宽度和高度,因此包含公式 Scratch.X1 的单元格依赖于矩形形状的宽度和高度单元格,因此使这些单元格成为先例。
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 支持和反馈,获取有关如何接收支持和提供反馈的指南。