GG24
GG24

Reputation: 303

How change the style of a shape-text in vba?

I changed the size of text with the following line of code

shp.CellsSRC(visSectionCharacter, 0, visCharacterSize).FormulaU = " 3pt"

I'd like to change the style (to Bold) and color of the shape text with the same pattern of code ?

I didn't find the exact "formula", would you know how I could do that ?

Thank you very much in advance

Edit : I found this line for the color :

shp.CellsSRC(visSectionCharacter, 0, visCharacterColor).FormulaU = "THEMEGUARD(RGB(255,0,0))"

Upvotes: 2

Views: 1592

Answers (1)

PeterT
PeterT

Reputation: 8557

I'm not sure why there is no enumeration for setting the Style. In any case, it's Column 2 in the shape properties. So use

shp.CellsSRC(visSectionCharacter, 0, 2).FormulaU = 17

to set your text to Bold.

How do I know this you ask? Based on the Microsoft reference on Understanding the Shape Sheet, there is a helpful snippet of code to use.

First, select the shape in your drawing that you want to see information about the properties. Then open up the Shape Properties window in the Visio editor (not in the VBE) -- you can get there by viewing the Developer ribbon, then click on the Show ShapeSheet icon

enter image description here

In the shape properties window, scroll down until you see the Characters section. You MUST select one of the cells in the properties window. The example here has selected the Style column.

enter image description here

Once you have done this, then run the following code snippet below and you'll get the information you need in the Immediate Window of the VBE.

Public Sub DebugPrintCellProperties()
    ' Abort if ShapeSheet not selected in the Visio UI
    If Not Visio.ActiveWindow.Type = Visio.VisWinTypes.visSheet Then
        Exit Sub
    End If
    Dim cel As Visio.Cell
    Set cel = Visio.ActiveWindow.SelectedCell
    'Print out some of the cell properties
    Debug.Print "Section", cel.Section
    Debug.Print "Row", cel.Row
    Debug.Print "Column", cel.Column
    Debug.Print "Name", cel.Name
    Debug.Print "FormulaU", cel.FormulaU
    Debug.Print "ResultIU", cel.ResultIU
    Debug.Print "ResultStr("""")", cel.ResultStr("")
    Debug.Print "Dependents", UBound(cel.Dependents)
    ' cel.Precedents may cause an error
    On Error Resume Next
    Debug.Print "Precedents", UBound(cel.Precedents)
    Debug.Print "--------------------------------------"

End Sub

This will tell you the Section, Row, and Column to use when you call CellsSRC. What I did was to figure out the property, then I manually set the text to BOLD and viewed the results of DebugPrintCellProperties again to see that the FormulaU = 17 for bold.

Upvotes: 2

Related Questions