Inserting a string variable into Visio Cell

Hi,

I have a string variable foo which i want to insert into a visio cell. The sample code I have is as follows:

foo = "someString"

vsoShape.CellsSRC(visSectionProp, visRowProp, visCustPropsValue).FormulaU = foo

but this gives a run-time error #NAME?. The same result occurs when i try vsoShape.CellsSRC(visSectionProp, visRowProp, visCustPropsValue).FormulaU = "foo"

 

The forums suggest using triple quotes but I can't really get away with doing: 

vsoShape.CellsSRC(visSectionProp, visRowProp, visCustPropsValue).FormulaU = """someString""" as the variable always changes.

Is there any way to solve it? If it has been discussed before, could you point me to the correct forum please? Thanks in advanced.

mitchwxy

September 22nd, 2010 3:01am

As a suggestions first check to see if the cellexists

dim strPropertyName as string = "prop.myproperty"

 

 

If visShape.CellExists(strPropertyName, False) = True Then

visCell = visShape.Cells(strPropertyName)

visCell.FormulaU = strValue

end if

al

 

Free Windows Admin Tool Kit Click here and download it now
September 22nd, 2010 5:55am

Hi Al,

Thanks for your reply.

I have assumed and set visCell As Visio.Cell. Running that code, I still have a run-time error '91' "Object variable or With block variable not set" for the line 

visCell = visShape.Cells(strPropertyName)

I guess this means that the cell does exist (since we actually enter the if statement) but still doesn't solve the problem that i'm having.

September 22nd, 2010 7:21am

did you define a

dim visCell as visio.cell

?

I usually get one of thos #NAME errors when I try to access a cell that doesn't exist (i.e. visio couldn't find the object with that name). That's why I test before I try to do anything with something I had the responsibility of building. There's also a routine (StringToFormulaForString) in the visio sdk that can be used to wrap/format strings before putting them into cells. You can also try something like this

al

 

 

'

 

 

'

 

 

'

 

 

Public Sub SetCustomPropertyFormula( _

 

 

ByVal customPropertyShape As Visio.Shape, _

 

 

ByVal rowNameU As String, _

 

 

ByVal universalSyntaxFormula As String)

 

 

Const CUST_PROP_PREFIX As String = "Prop."

 

 

Dim customPropertyCell As Microsoft.Office.Interop.Visio.Cell

 

 

Dim visioApplication As Microsoft.Office.Interop.Visio.Application

visioApplication =

 

CType(customPropertyShape.Application, _

Microsoft.Office.Interop.Visio.

 

Application)

 

 

Try

 

 

' Verify that all incoming string parameters are not of zero

 

 

' length, except for the ones that have default values as ""

 

 

' and the output parameters.

 

 

If (rowNameU.Length() = 0) Then

 

 

Throw New System.ArgumentNullException("rowNameU", _

 

 

"Zero length string input.")

 

 

End If

 

 

If (universalSyntaxFormula.Length() = 0) Then

 

 

Throw New System.ArgumentNullException( _

 

 

"universalSyntaxFormula", "Zero length string input.")

 

 

End If

 

 

' See if the shape has a custom property Value cell with the

 

 

' universal row name. If no cell exists, display an error

 

 

' message and exit this procedure.

 

 

If Not CBool(customPropertyShape.CellExistsU( _

CUST_PROP_PREFIX & rowNameU,

 

CShort(False))) Then

 

 

If visioApplication.AlertResponse = 0 Then

MsgBox(

 

"This shape " _

&

 

"does not have a custom property " & vbCrLf & _

 

 

"with the universal name '" & vbCrLf & rowNameU & _

 

 

"'.")

 

 

Return

 

 

End If

 

 

End If

 

 

' Get the Cell object. Note the addition of "Prop." to the name

 

 

' given to the cell.

customPropertyCell = customPropertyShape.CellsU( _

CUST_PROP_PREFIX & rowNameU)

 

 

' change when the width of the shape changes.

customPropertyCell.FormulaU = universalSyntaxFormula

 

 

Catch Err As Exception

System.Diagnostics.

 

Debug.WriteLine(Err.Message)

 

 

End Try

 

 

End Sub

Free Windows Admin Tool Kit Click here and download it now
September 22nd, 2010 2:30pm

Hi Al,

Yes, I did define it as a Visio.Cell

I tried using the StringToFormulaForString function but it gives a "compile error: Sub or Function not defined". Is there any link which shows the code for the function StringToFormulaForString does? I could then modify it to create my own custom Sub.

With regards to the code you pasted, it doesn't seem to work either. I've got a feeling that we can't simply put any string in the Values column of a "Prop.xxx" row. The string probably needs to be configured in a certain way.

September 29th, 2010 10:23am

You're correct in that not all strings may be accepted. Some special characters are not. What is the value in your string variable?

al

 

Free Windows Admin Tool Kit Click here and download it now
October 3rd, 2010 5:49pm

I have the exact same problem and found a code that worked for me here:

http://www.office-archive.com/72-visio-vba/4203fd2d2eaf62e3.htm

/Staffan Sderholm

June 5th, 2013 5:57pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics