Getting Shapesheet's Character Section Info in VB

M

MikeBTP

I understand how to get various Character properties from the shapesheet in
VB using the Cells("Char.xxx[1]") (ie: Cells("Char.Font[2]")) but how do
you get or set the first column of the Character section that denotes the
number of characters affected?
Example:
A shape with 16 characters of text might have 3 rows under Character in the
Shapesheet.
Row 1 has 6 characters with a Color of 0
Row 2 has 8 characters with a Color of 4
Row 3 has 2 characters with a Color of 0

The first column under the Character section is "labelled" 6
The second column under the Character section is "labelled" 8
The third column under the Character section is "labelled" 2

How do I get those values from that field in VB? And how do you create a row
with a specific value within VB?

Thanks for any help
Mike
 
H

Heidi Munson [MSFT]

The characters object can to set text formatting and to analyze text in the
shape.

Markus' linked sample below show use the characters object to add formatting
and there by often add rows to the characters section. You can find other
examples that use the characters object to set formatting and add fields in
the Visio 2003 SDK. Once you've installed the SDK, from the Microsoft
Office Visio 2002 SDK menu item off programs select the Code Librarian
viewer. In the viewer select a language (VB6, VB.net or C#) then go to the
shapes node and scroll down to text. There are two text formatting samples.
The Visio 2003 SDK can be downloaded here. ,
http://www.microsoft.com/downloads/...bd-b0bb-46e7-936a-b8539898d44d&displaylang=en

While you can't actually get the first column labels you can get similar
information form the Characters object. The Characters object deals with
fields a bit differently then the labeling in the ShapeSheet window. To
analyze the text in the shape, use the .RunBegin and .RunEnd properties of
the Characters object. The VBA code below provides a simple example of
analyzing text using RunBegin and RunEnd. It expects the active window to
be a drawing type window and for at least one shape to be selected. It
analyzes the text in the first shape in the selection and find runs of text
in the shape that corresponds to each of the rows in the characters section.

Sub GetCharRows()

'For simplicity work on the first shape in the selection
Dim vsoShape As Visio.Shape
Set vsoShape = ActiveWindow.Selection.Item(1)
Dim intCharCount As Integer
Dim intRunEnd As Integer
Dim intRunBegin As Integer
Dim i As Integer
i = 0

Dim vsochars As Visio.Characters
' The initial characters object return from the Characters Property of the
shape spans all the text in the shape,
Set vsochars = vsoShape.Characters
intCharCount = vsochars.CharCount

While (i + 1 < intCharCount)
' Set the characters object to span one character
vsochars.Begin = i
vsochars.End = i + 1
' Find the set of characters that share formatting with this character
intRunEnd = vsochars.RunEnd(Visio.VisRunTypes.visCharPropRow)
intRunBegin = vsochars.RunBegin(Visio.VisRunTypes.visCharPropRow)
' Set the characters object to span this run
vsochars.Begin = intRunBegin
vsochars.End = intRunEnd
' Update i so that the next time through the loop, we'll look at the
first character after this run.
i = intRunEnd
' Output some helpful information about this run.
Debug.Print "Row Info: Row Number = " &
vsochars.CharPropsRow(Visio.visBiasLeft) & " CharCount " &
vsochars.CharCount
Debug.Print " Run Begin = " & intRunBegin & " Run End " & intRunEnd
'The text in this run may contain returns to make it easier to see what
text belongs to each run, wrap the text in tags.
Debug.Print "<Text>" & vsochars & "</Text>"

Wend

End Sub

-Heidi
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.

Markus Breugst said:
Hello Mike,

the value of the first column is set "indirectly" by defining the BEGIN and
END position of the characters to be formatted. Please have a look at this
news contribution for some example code:

http://groups.google.de/groups?q=vi...=eR0DR7e#[email protected]&rnum=1

I don't think that there is a way to GET the first column values.

Hope this helps.

Best regards,
Markus

MikeBTP said:
I understand how to get various Character properties from the shapesheet in
VB using the Cells("Char.xxx[1]") (ie: Cells("Char.Font[2]")) but how do
you get or set the first column of the Character section that denotes the
number of characters affected?
Example:
A shape with 16 characters of text might have 3 rows under Character in the
Shapesheet.
Row 1 has 6 characters with a Color of 0
Row 2 has 8 characters with a Color of 4
Row 3 has 2 characters with a Color of 0

The first column under the Character section is "labelled" 6
The second column under the Character section is "labelled" 8
The third column under the Character section is "labelled" 2

How do I get those values from that field in VB? And how do you create a row
with a specific value within VB?

Thanks for any help
Mike
 

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