首页 > 解决方案 > Visio 使用 VBA 更改形状数据/属性

问题描述

对于一个项目,我正在创建一个用户窗体,它从文本框中读取值并使用数据生成形状。因此,在删除形状后,我想更改形状数据行,例如“Prop.SO_Name”。

当我使用

shp.CellsU("Prop.SO_Name").FormulaU = """Test"""

它工作得很好。但我想从文本框中读取一个值。我试过了

Dim cell As Visio.cell
Set cell = shp.Cells("Prop.SO_Name")
cell.FormulaU = TextBox2.Value

但它返回运行时错误。我也试过

Dim str as String
str = Textbox2.value
Dim cell As Visio.cell
Set cell = shp.Cells("Prop.SO_Name")    
cell.FormulaU = str

结果相同。

我查看了 FormulaU 属性的文档,但显然他们这样做了,就像我尝试过的一样。显然我错过了一些东西。

标签: vbams-officevisio

解决方案


`尝试使用

Dim cell As Visio.cell  
Set cell = shp.Cells("Prop.SO_Name")  
cell.FormulaU = chr(34) & UserForm1.TextBox2.Value & chr(34)

更新您尝试将字符串写入 ShapeSheet 单元格!字符串中的双引号是告诉 VB[A] 制作一个带有嵌入引号字符的字符串的一种方法。


推荐阅读