Search code examples
vbams-officevisio

Visio Change Shape Data/Properties with VBA


for a project I am creating a UserForm that reads values from textboxes and generates Shapes with the data. So after dropping a shape I want to change the Shape Data rows, for example "Prop.SO_Name".

When I use

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

It works just fine. But I want to read a value from the textbox. I tried

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

But it returns a runtime error. I also tried

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

With the same result.

I looked into the documentation for the FormulaU Property but they do it, apparently, just like I tried. Clearly I am missing something.


Solution

  • `Try use

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

    Update You try write string to ShapeSheet cell ! The double quotes within the string is one way to tell VB[A] to make a string with embedded quote mark characters in it.