Table of contents

Cell.Formula 属性 (Visio)Cell.Formula Property (Visio)

office 365 dev account|上次更新日期: 2018/3/13
2 参与人员

获取或设置一个单元格的公式。读/写。Gets or sets the formula for a Cell object. Read/write.


表达式公式expression . Formula

表达式_一个表示单元格对象的变量。_expression A variable that represents a Cell object.

返回值Return Value



如果单元格的公式受 GUARD 函数保护,您必须使用FormulaForce属性来更改单元格的公式。If a cell's formula is protected with the GUARD function, you must use the FormulaForce property to change the cell's formula.

请注意 从 Microsoft Visio 2000 开始,可以使用本地和通用名称来指代 Visio 形状、 主控形状、 文档、 页面、 行、 加载项、 单元格、 超链接、 样式、 字体、 主控形状快捷方式、 用户界面对象和图层。当用户为某个形状命名时,例如,用户指定的本地名称。从 Microsoft Office Visio 2003 开始,ShapeSheet 电子表格中单元格的公式和值显示只有通用名称。(在先前版本中,通用名称都不可见的用户界面中。)Note Beginning with Microsoft Visio 2000, you can use both local and universal names to refer to Visio shapes, masters, documents, pages, rows, add-ons, cells, hyperlinks, styles, fonts, master shortcuts, UI objects, and layers. When a user names a shape, for example, the user is specifying a local name. Beginning with Microsoft Office Visio 2003, the ShapeSheet spreadsheet displays only universal names in cell formulas and values. (In prior versions, universal names were not visible in the user interface.)

作为开发人员,您可以在程序中使用通用名称时,您不希望每次本地化解决方案时都更改名称。使用Formula属性来获取本地语法的单元格的公式字符串或本地和通用语法混合使用,可将其设置。使用FormulaU属性来获取或分析通用语法公式。在使用FormulaU时,小数点始终是"。"、 分隔符始终是"",并且必须使用通用的单位字符串 (通用字符串的详细信息,请参阅关于度量单位)。As a developer, you can use universal names in a program when you don't want to change a name each time a solution is localized. Use the Formula property to get a cell's formula string in local syntax or to use a mix of local and universal syntax to set it. Use the FormulaU property to get or parse a formula in universal syntax. When you use FormulaU , the decimal point is always ".", the delimiter is always ",", and you must use universal unit strings (for details on universal strings, seeAbout Units of Measure).


此 Microsoft Visual Basic for Applications (VBA) 宏显示如何使用Formula属性来设置 ShapeSheet 单元格的公式。它上一个页,成为弓形绘制矩形或曲线通过将该形状的线条更改为弧形使矩形的线条。然后它绘制一个内部矩形的第一个矩形的弓形线条内。This Microsoft Visual Basic for Applications (VBA) macro shows how to use the Formula property to set the formula for a ShapeSheet cell. It draws a rectangle on a page and bows, or curves the lines of the rectangle by changing the shape's lines to arcs. Then it draws an inner rectangle within the bowed lines of the first rectangle.

Public Sub Formula_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
© 2018 Microsoft