如何在 Visio 中使用 VBA 设置自定义单元格属性值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14407453/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:14:32  来源:igfitidea点击:

How to set custom cell property values with VBA in Visio?

vbavisiovisio-vba

提问by jersan

I have a drawing with hundreds of shapes, and they all have the same data set applied to them. In this case let's say I want to change the value in row "Prop.Row_5" to 0001 for every shape.

我有一张包含数百个形状的绘图,它们都应用了相同的数据集。在这种情况下,假设我想将每个形状的“Prop.Row_5”行中的值更改为 0001。

Currently I have:

目前我有:

Sub Macro1()
    Dim vsoPage As Visio.Page, vsoShape As Visio.Shape
    Dim vsoStrng As String

    For Each vsoPage In ThisDocument.Pages
        For Each vsoShape In vsoPage.Shapes
            vsoShape.CellsSRC(visSectionProp, 4, visCustPropsValue).FormulaU = "0001"

        Next
    Next

End Sub

This is one of several different methods I have tried, nothing seems to work. Can somebody clear this up for me?

这是我尝试过的几种不同方法之一,似乎没有任何效果。有人可以帮我解决这个问题吗?

回答by Clon

Your code should work if the property is a number, or you can put it without commas,

如果属性是一个数字,你的代码应该可以工作,或者你可以不加逗号,

Dim vsoPage As Page
Dim vsoShape As Shape

For Each vsoPage In ThisDocument.Pages
    For Each vsoShape In vsoPage.Shapes
        vsoShape.CellsSRC(visSectionProp, intRowNum, _
            visCustPropsValue).FormulaU = 1
    Next
Next

But, if the property is a string, you must use three commas, like

但是,如果属性是字符串,则必须使用三个逗号,例如

        vsoShape.CellsSRC(visSectionProp, intRowNum, _ 
            visCustPropsValue).FormulaU = """0001"""

This is because the formula itself is a string which evaluates to a string only if it contains the "" characters inside. Otherwise, if looks for a variable, function or cell named as the string you entered.

这是因为公式本身是一个字符串,只有在其中包含 "" 字符时才计算为字符串。否则, if 将查找以您输入的字符串命名的变量、函数或单元格。

Hope this helps you.

希望这对你有帮助。

Regards,

问候,