如何在vba中更改形状文本的样式?

问题描述 投票:1回答:1

我用下面的代码行更改了文本大小

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

我想使用相同的代码模式将形状文本的样式(更改为粗体)和颜色?

我没有找到确切的“公式”,您知道我该怎么做吗?

非常感谢您

编辑:我发现这行是颜色的:

shp.CellsSRC(visSectionCharacter, 0, visCharacterColor).FormulaU = "THEMEGUARD(RGB(255,0,0))"
vba visio
1个回答
0
投票

我不确定为什么没有enumeration来设置样式。无论如何,形状属性中都是第2列。因此使用

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

将文本设置为粗体

我怎么知道你问的?基于Understanding the Shape Sheet上的Microsoft参考,有一个有用的代码段可供使用。

首先,在图形中选择要查看有关属性信息的形状。然后在Visio编辑器中打开“形状属性”窗口(在VBE中为[not)-您可以通过查看Developer功能区到达那里,然后单击Show ShapeSheet图标

enter image description here

在形状属性窗口中,向下滚动,直到看到“字符”部分。您必须在属性窗口中选择一个单元格。此处的示例选择了“样式”列。

enter image description here

一旦完成此操作,然后在下面运行以下代码片段,您将在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

这将告诉您调用CellsSRC时要使用的节,行和列。我要做的是找出该属性,然后手动将文本设置为BOLD,然后再次查看DebugPrintCellProperties的结果以查看FormulaU = 17为粗体。

© www.soinside.com 2019 - 2024. All rights reserved.