Programmatically add a formula to a Shape Data Value without quote

N

NG_AU

Hi Guys

I have a routine SetCustomPropertyValue (originally from SDK from memory) &
I now want to add a formula in the value column of the Shape Data section of
the shapes shape sheet.

I am using the call below

Call VisioShapeEvents.SetCustomPropertyValue _
(vsoShape, _
"CPURAMDisk", _
"Prop._VisDM_CPU_MHz & " & Chr(34) & " / " & Chr(34) & "
& Prop._VisDM_Memory_MB & " & Chr(34) & " / " & Chr(34) & "&
Prop.HardDriveSize", _
231)

Unfortunately I cannot get the formula without the leading & trailing quotes
around the formula, notice I have tried CHR(34) this works find, but I cant
get rid of the leading & trailing "s.

Any one ever been able to do this ?

TIA

NG
 
J

JuneTheSecond

Please, show us original formula that you wish, as it is human unreadable.
Are there any reason why you are going to use SetCustomPropertyValue?
I think there is more simple way, if you wish just add formula to the custom
property. For example ObjShape.Cells("Prop.Row_1").Formula= "Width".

--
Best Regards.

JuneTheSecond
Now, visual calculation is more visual.
http://www.geocities.jp/visualcalculation/english/index.html
 
C

Chris Roth [Visio MVP]

Hi NG,

A couple of tips:

1. Create a separator variable, so you can actually see what you are doing
2. You actually need "&" between the parts of the formula in the
ShapeSheet, not just in your VBA code. For instance, you could have a
formula that looks like this: Prop.X = Width & Height, which just
concatenates two numbers together.

Have a look at this snippet:


Sub TestSetLongFormula()

' Get a selected shape:
Dim shp As Visio.Shape
Set shp = Visio.ActiveWindow.Selection(1)

' Formula that works looks like this in the ShapeSheet:
'
' Prop._VisDM_CPU_MHz&" / "&Prop._VisDM_Memory_MB&" /
"&Prop.HardDriveSize

' Define a separator so that you can test without going crazy:
Dim sep As String
sep = "&" & Chr(34) & " / " & Chr(34) & "&"

Debug.Print sep
' Looks like this:
' Prop._VisDM_CPU_MHz&" / "&Prop._VisDM_Memory_MB&" /
"&Prop.HardDriveSize

' Build the formula
Dim frml As String
frml = "Prop._VisDM_CPU_MHz" & sep & "Prop._VisDM_Memory_MB" & sep &
"Prop.HardDriveSize"
Debug.Print frml

' Set the formula for the cell:
shp.Cells("Prop.MyCell").Formula = frml

End Sub


--
Hope this helps,

Chris Roth
Visio MVP


Visio Guy: Smart Graphics for Visual People

Articles: http://www.visguy.com
Shapes: http://www.visguy.com/shapes
Dev: http://www.visguy.com/category/development/
Forum: http://www.viguy.com/vgforum
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top