Change the font using VBA

Started by ziko, April 02, 2010, 07:33:43 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ziko

Hello,

I am adding a shape dynamically and assign a text to it.
The text has multi lines. After doing that the text displayed is much larger than the shape so I decided to resize it, the code executes without any error but I couldn't see the new size.

Dim lShape As Visio.Shape
..... Add the shape...
lShape.Text = line1 & vbCrLf & line2 & vbCrLf & line3
lShape.Cells("Char.Size").Formula = "= 5 pt."
lShape.BringToFront


It took me a day to find out the name of the cell: "Char.Size" is there a list of these names? and where can I find them?
This line executes without any error but it is not reflecting the new size on the drawing.
lShape.Cells("Char.Size").Formula = "= 5 pt."

Another question: How can I change the Format/Text/Paragraph/Spacing/Line programatically in the drawing it shows 140% and I want to make it 80 % using VBA code so what is the local specific cell name for that?

Thank you
Any help is much appreciated,
Ziko

Yacine

This is a quite exhaustive list.
http://msdn.microsoft.com/en-us/library/aa246643(office.11).aspx
However, you'll be faster if you write a new row in the user section of your shape and reference the cell you need, by clicking on it while editing your new cell.
That's how you'll find the name of text formats you need.
Hope that was not too complicated.
Yacine

Jumpy

In this case don't use formula but result:

lShape.Cells("Char.Size").Result("pt") = 5

The Result property needs a unit in "", in this case pt = Points.

If you still want to use formula you could leave out the '=' in the String, it's not necessary. And what sometimes works is sth. like this:

Dim strHelp as String
strHelp = Chr(34) & "5 pt." & CHR(34)
lShape.Cells("Char.Size").Formula = strHelp


For your second problem you should try:
lShape.Cells("Para.Line").Formula / or Result

One way to get to cell names is to look them up in the ShapeSheet.

ziko

Thanks a lot for the ShapeSheet reference link, I was looking for it for couple of days on the net and couldn't find it.

The code executes without errors but the font size and line spacing still not changed.
I noticed in the ShapeSheet reference under Char Size section the following note:
If the drawing is scaled, the text size remains the same.
How do I know if my shape is scaled? and how can I set this property to false so the text gets re-sized?

Any help is much appreciated I have to deliver this project soon and I still couldn't get it working and I am new to visio and automation field.
Thank you,
Ziko


Visio Guy

Hi Ziko,

Is your shape a group of sub-shapes? If your text is on a sub-shape inside the group, then setting the top-level Char... and Para... cells won't change the text properties of shapes inside the group. You'll have to go to the sub-shapes with code like: shpGrp.Shapes.Item(1).Cells("Char.Size")

This is the slight difference between the UI and automation. In the UI, if you select a shape and change some formatting, Visio applies it to sub-shapes as well. In code, you are setting cells, so you don't get this recursion into the group members.
For articles, tips and free content, see the Visio Guy Website at http://www.visguy.com
Get my Visio Book! Using Microsoft Visio 2010

ziko

I am adding the shape "Oval callout" dynamically from the Annotation stencil:ANNOT_U.VSS
And you are absolutely right, that annotation shape is a group. And when I used
lShape.Shapes.Item(2).Cells("Char.Size")

it resizes.

Thank you so much,
Ziko