I want to change the font in just the first line of text in the shape.
I'm using the following code to change the fill of the shape and the font color.
The text is contained in the Prop.Name field of the Shape Data.
Dim pg As Visio.Page
Dim shp As Visio.Shape
Dim oShpChar As Visio.Characters
For Each pg In ActiveDocument.Pages
For Each shp In pg.Shapes
Set oShpChar = shp.Characters
' cellexists test is necessary to avoid links and other shapes without data
'Debug.Print shp.CellsU("Prop.Color_Code").ResultStr(0)
If shp.CellExists("Prop.Color_Code", False) Then
Select Case shp.CellsU("Prop.Color_Code").ResultStr(0)
Case "Red"
shp.CellsU("FillForegnd").Formula = visRed
shp.CellsU("FillBkgnd").Formula = visRed
oShpChar.CharProps(visCharacterColor) = 1
'I want to do something like the line below.
'shp.CellsU("Prop.Name").FontSize = 10
Case "Blue"
shp.CellsU("FillForegnd").Formula = visBlue
shp.CellsU("FillBkgnd").Formula = visBlue
Case "Green"
shp.CellsU("FillForegnd").Formula = visGreen
shp.CellsU("FillBkgnd").Formula = visGreen
Case Else
shp.CellsU("FillForegnd").Formula = visGray
shp.CellsU("FillBkgnd").Formula = visGray
End Select
End If
Next
Next
Is there a way to do this?
Scott
How are you entering the text for display? How are you creating multiple rows?
Which version of Visio, can you upload a sample...vs preferred file format.
Wapperdude
Thanks for replying.
The text comes from a spreadsheet with 4 columns Name, ReportsTo, Title, and Color_Code
The org chart is then created through automation (vba) using a MS Access database.
The code above to change the colors is in Visio 2010 right now but will be moved to the Access code once its finalized.
In the attached file, place OrgTestSample.xlsx in the root of the C drive. This is where the Access code is looking for it.
Open up Access and click the create button. The chart gets created and applies the colors. I want to be able to modify the font size of the first line in the shape (Prop.Name)for the red shapes.
Scott
Similar problem: http://visguy.com/vgforum/index.php?topic=7716.msg32794;topicseen#msg32794
Yacine,
I looked at the code and downloaded the attachments. I didn't see anything there related to changing the font size of a particular line of text. ("Prop.Name") item in my case.
It all looked like it was relating to adding text. If I ran the code it just placed some red text behind the object.
Let me know if I'm missing something.
Scott
The purpose of the example was to show how to easily add/omit text and how to easily format it. It did not address how to initially grab the text from some data source. Presumably, that's already solved.
For example, prop.name might be the 1st shape. You can:
1) preset all formatting prior to data entry
2) manually format after data entry
3) modify program to make desired formats when prop.name is placed
4) modify all appropriate shapesheet to detect when prop.name is placed as text, and adjust necessary shapesheet cells. This can be problematical for a variety of reasons.
HTH,
Wapperdude
What I intended to say was that is makes more sense to handle text fields in separate sub-shapes than trying to split it afterwards. Your first line of text is somewhere a separate field. Keep it so and make the labelling accordingly.
Thanks for your replies. I still don't understand how to select just the first line of text I need to change.
I'll keep Googleing
Scott
Can you upload an example? VSD format preferred. That will help with clarifying things and get us all on the same page.
Wapperdude
All the files are attached in my second post. They are Visio2010. I can down invert them next week
Scott
I think I understand. Basically, you need to 1st find a shape that has a given property, e.g., prop.name. Then you need to determine what shape receives the prop.name value. That is, what shape is dependent on the prop.name? This will be a sub shape of the shape containing prop.name.
The newer Visio versions have a cells dependent property in their object model, see Cell.Dependents Property (Visio), https://msdn.microsoft.com/en-us/library/office/ff767522.aspx (https://msdn.microsoft.com/en-us/library/office/ff767522.aspx). Don't know if this goes back to Visio10.
Another approach would be to grab the prop.name text string, then iterate thru the shapes...including subshapes...compare the text strings for a match.
There are posts in the forum re searching subshapes.
Wapperdude
I know its not an answer to the question, but definitely a solution for the problem. Sorry for coming so late with it - I'm getting forgetful.
Make sure in your configuration to leave the fields separated (title and other fields not merged in one field). Then use the tool shown here: http://visguy.com/vgforum/index.php?topic=6318.msg25957#msg25957 .
Now select the title sub-shape and format it to whatever you like.
For sake of completeness, the attached shows how to find desired text and do some formatting. Note, the code "hard copies" the data property identity, e.g., Prop.name in this case.
Wapperdude
Here's an alternate version. Since it is only the first line that is being changed, then, putting everything into a single shape is actually easier than the multiple subshape approach. Attached is code with example.
Note: The assumption is that any text formatting, e.g. bold, etc, has been uniformly applied to all text.
Wapperdude
Sorry, I have been away. Thanks for looking. I will check it out on Monday.
Scott