CellSRC

Started by dmajic, October 28, 2009, 04:19:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

dmajic

I'm trying to create a Visio VBA app that will allow me to update a group of shapes with some text. I want to input the initial text from an excel spreadsheet. I cannot seem to populate the visCustPropsValue with a value from a variable. The following code:

 
  intPropRow2 = vsoShape.AddRow(visSectionProp, visRowLast, visTagDefault)
   vsoShape.CellsSRC(visSectionProp, intPropRow2, visCustPropsLabel).FormulaU = """Group"""
   vsoShape.CellsSRC(visSectionProp, intPropRow2, visCustPropsValue).FormulaU = SomeTextVariable


gives me a #Name? error

What's the deal with the """ quotes anyway?

JuneTheSecond

Hi,

"""Group""" shoud be """"Group"""" in VBA.
"""Group""" is correct in ShapeSheet.

Best Regards,

Junichi Yoda
http://june.minibird.jp/

wapperdude

#2
The Prop section seems kinda finicky about syntax.   :P

But, to shove a variable into the "value" cell, here's some code to help you move forward.   ;D  It requires "chr(34)" to function correctly.  I show two different syntaxes, both work.   ::)  I have one Custom Property row, called MyText, instead of Prop.row_1.

Sub CUsPpty()       
Dim vsoShp As Visio.Shape
Dim txtVar As String
Dim vsoCell As Visio.Cell

txtVar = "Some more NEW text."

For Each vsoShp In ActivePage.Shapes
    Set vsoCell = vsoShp.CellsSRC(visSectionProp, 0, visCustPropsValue)
    vsoCell.FormulaForceU = Chr(34) & txtVar & Chr(34)
    'vsoShp.CellsU("Prop.MyText.Value").FormulaForceU = Chr(34) & txtVar & Chr(34)  'Ah, this works too!!!
Next

End Sub
Visio 2019 Pro

dmajic

Fantastic!

Chr(34) & txtVar & Chr(34) was the key.

I couldn't find that anywhere in the documentation and there are absolutely no reference books in the book stores.

Thank you.

Paul Herber

Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

twolsey

#5
Hello

When I use the portion of the suggested code below (Option 1), I tried to set values for multiple Shapesheet cells on different rows at the same time, I receive the "Unexpected End of File" error. Is there something different that I can do to make this way work.  By the way, the Option 2 option works.

thanks
Tony


Option 1

.....
           shpObj.CellsU("Prop.tagparent.Value").FormulaForceU = Chr(34) & var1 & Chr(34)
           shpObj.CellsU("Prop.descriptionparent.Value").FormulaForceU = Chr(34) & var2 & Chr(34)
           shpObj.CellsU("Prop.cable1parent.Value").FormulaForceU = Chr(34) & var3 & Chr(34)
......

Option 2

.....
            shpObj.CellsSRC(visSectionProp, 0, _
            visCustPropsValue).FormulaU = Chr(34) & var1& Chr(34)
           
            shpObj.CellsSRC(visSectionProp, 1, _
            visCustPropsValue).FormulaU = Chr(34) & var2 & Chr(34)
           
            shpObj.CellsSRC(visSectionProp, 2, _
            visCustPropsValue).FormulaU = Chr(34) & var3& Chr(34)
.....

wapperdude

#6
Reference:  https://learn.microsoft.com/en-us/office/vba/api/visio.shape.cellsu
CellsU ("somestring") raises an "Unexpected end of file" exception if "somestring" does not name an actual cell.

Since the syntax puts the cellname inside of dbl quotes, the expression for the cellname has to be precise...spelling, upper/lower case, etc.
Visio 2019 Pro