Take independent text and fill in custom properties

M

Mike

Hey guys I haven't used Visio much, but is there a way to take the label from
a shape and have it fill in the custom properties field?

After creating a layout with 40+ shapes double-clicking on them and adding a
label, I would like to take that label and have it populate the custom
properties label. Did I do this backwards?

TIA!!!
Mike
 
D

David Parker

If you put the formula
=GUARD(SHAPETEXT(TheText,129))
into the Value cell of a Custom Property in the ShapeSheet, then you will
get the shape text
 
J

John Goldsmith \(Visio MVP\)

Hello Mike,

The answer is yes, you did. Normally you would edit the Shape Data (custom
properties) and then add an inserted field to hold the respective text. For
example (assuming you already have a shape with a custom property name
MyCellName):

1) With the shape selected press F2 to edit the text

2) From the menu select Insert / Field...

3) From the Field dialog select Shape Data (or Custom Property) from the
category listbox on the left and 'MyCellName' from the field name listbox on
the right. Click OK.

4) Select your shape again and then Window / Show ShapeSheet and navigate
down to the Events section.

5) In the Events section add the following formula to the EventDblClick
cell: =DOCMD(1312) This will change the double click behaviour to open
the Custom Properties dialog instead of text editting.


Now that's not much good for your existing problem, so a little code might
help. Take a look at this link and then let me know if you have any
questions:

http://visualsignals.typepad.co.uk/vislog/2007/10/just-for-starte.html

....and here's the code, which you can paste into the 'ThisDocument' class
and run from there (make sure you have your shapes selected before you
actually run the code):

Private Sub TextToProps()
Dim shp As Shape
Dim i As Integer
Dim sText As String
Dim sel As Selection
Dim vCell As Cell
Dim sPropName As String
Dim iRow As Integer
sPropName = "MyCellName"

Set sel = ActiveWindow.Selection

For i = 1 To sel.Count
Set shp = sel(i)

'Get the original text
sText = shp.Text
shp.Text = ""

'Check property exists and if
'not add it to the shape
If shp.CellExists("Prop." & sPropName, 0) = True Then
iRow = shp.CellsRowIndexU("Prop." & sPropName)
Else
iRow = shp.AddNamedRow(visSectionProp, sPropName, visTagDefault)
End If
shp.CellsSRC(visSectionProp, iRow, visCustPropsLabel).FormulaU = "=""" &
sPropName & """"
shp.CellsSRC(visSectionProp, iRow, visCustPropsType).FormulaU = 0
shp.CellsSRC(visSectionProp, iRow, visCustPropsValue).FormulaU = "=""" &
sText & """"

'Now add the inserted field
With shp.Characters
.Begin = 0
.End = 0
.AddCustomFieldU "Prop." & sPropName, visFmtNumGenNoUnits
End With
Next i

End Sub

Hope that helps.

Best regards

John


John Goldsmith (Visio MVP)
www.visualSignals.typepad.co.uk
www.visualSignals.co.uk
 
C

Chris Roth [Visio MVP]

In case anybody is wondering what the '129' is in David's formula,
well...my guess is this:

The SHAPETEXT formula takes a flag as a second argument. The possible
values for that argument are:

0 Show text exactly as shown in shape.
1 Include discretionary hyphens.
2 Don't include expanded text in fields.
4 Convert tabs to a single space.
8 Convert tabs to a set of spaces.
16 Convert carriage returns and line feeds to spaces.
32 Convert typographer quotes to regular quotes.
64 Convert adjacent white space to a single space.

If you add all of these options together, you get 129, which means "ALL
OPTIONS", so to speak. This also means that the number should also
probably be 127, not 129.

--
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