本文介绍了如何在 vba 中更改形状文本的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码行更改了文本大小

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

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

我没有找到确切的公式",你知道我怎么做吗?

非常感谢您提前

我找到了这一行颜色:

shp.CellsSRC(visSectionCharacter, 0, visCharacterColor).FormulaU = "THEMEGUARD(RGB(255,0,0))"
解决方案

我不知道为什么没有

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

完成此操作后,运行下面的代码片段,您将在 VBE 的立即窗口中获得所需的信息.

公共子DebugPrintCellProperties()' 如果未在 Visio UI 中选择 ShapeSheet 则中止如果不是 Visio.ActiveWindow.Type = Visio.VisWinTypes.visSheet 那么退出子万一Dim cel As Visio.Cell设置 cel = Visio.ActiveWindow.SelectedCell'打印出一些单元格属性Debug.Print "Section", cel.SectionDebug.Print "Row", cel.RowDebug.Print "Column", cel.ColumnDebug.Print "Name", cel.NameDebug.Print "FormulaU", cel.FormulaUDebug.Print "ResultIU", cel.ResultIUDebug.Print "ResultStr("""")", cel.ResultStr("")Debug.Print "Dependents", UBound(cel.Dependents)' cel.Precedents 可能会导致错误出错时继续下一步Debug.Print "Precedents", UBound(cel.Precedents)Debug.Print "--------------------------------------"结束子

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

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))"
解决方案

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

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.

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.

这篇关于如何在 vba 中更改形状文本的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 03:21