首页 > 解决方案 > Visio VBA:如何使组织结构图中的所有文本加粗

问题描述

我想简化在 Visio 中更新我的组织结构图。到目前为止,我从这里借用了一个宏https://bvisual.net/2010/01/28/applying-selected-datagraphic-to-the-whole-document/并写在下面。我想对其进行调整以对带有形状的文本格式进行一些更改,例如使字体变粗并可能更改其颜色。我发现很难在网上找到这样的例子,所以任何帮助/建议都将不胜感激。

 Public Sub ApplyDataGraphicToDocument()
    Dim mstDG As Visio.Master
    Dim shp As Visio.Shape
    Dim pag As Visio.Page
    Dim firstProp As String

       If Visio.ActiveWindow.Selection.Count = 0 Then
           MsgBox "Please select a shape which already has data graphics"
           Exit Sub
       Else
           Set shp = Visio.ActiveWindow.Selection.PrimaryItem
          If shp.DataGraphic Is Nothing Then
               MsgBox "Please select a shape which already has data graphics"
              Exit Sub
           Else
              'Get the shapes DataGraphic master
              Set mstDG = shp.DataGraphic
               'Get the name of the first Shape Data row
              firstProp = "Prop." & _
 shp.CellsSRC(Visio.visSectionProp, 0, 0).RowNameU
           End If
      End If

       For Each pag In Visio.ActiveDocument.Pages
           If pag.Type = visTypeForeground Then
               For Each shp In pag.Shapes
           'Check that the named Shape Data row exists
                  If shp.CellExistsU(firstProp, Visio.visExistsAnywhere) Then
                      'Set the DataGraphic
                      shp.DataGraphic = mstDG
                                       End If
              Next
          End If
      Next

  End Sub

标签: vbaformattingvisio

解决方案


您可以修改默认的 OrgChart 形状,尽管它不受官方支持。要更改默认形状(使其字体加粗),您需要编辑这些 OrgChart 形状的模板(母版)。在同一个博客中,您可以在此处找到有关自定义组织结构图的更多信息:https ://bvisual.net/2012/05/08/creating-a-custom-org-chart-template-with-extra-properties

过程大致相同,只是不添加属性,而是将文本加粗。


推荐阅读