You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Visio中通过VBA为流程框创建带文本的自定义通知图标?

Visio自定义深蓝色通知图标VBA实现方案

核心实现思路

  • 自定义深蓝色圆形图标,内置可编辑的编号文本字段
  • 将图标绑定为流程框的子形状,实现随框移动、缩放的“边框附属”效果
  • 支持批量为选中的流程框添加图标

VBA代码实现

Sub AddCustomNotificationIcon()
    Dim vsoPage As Visio.Page
    Dim vsoTargetShape As Visio.Shape
    Dim vsoNotificationIcon As Visio.Shape
    Dim iconSize As Double
    Dim borderOffset As Double
    Dim inputNumber As String
    
    ' 图标基础参数(可按需调整)
    iconSize = 0.25    ' 图标尺寸(英寸)
    borderOffset = 0.05 ' 图标与流程框边框的间距
    
    ' 获取当前活动页面
    Set vsoPage = Visio.ActivePage
    If vsoPage Is Nothing Then
        MsgBox "请先打开一个Visio页面", vbExclamation
        Exit Sub
    End If
    
    ' 遍历选中的流程框形状
    For Each vsoTargetShape In vsoPage.Application.ActiveWindow.Selection
        ' 仅处理标准流程框(可根据实际形状的Master名称调整判断条件)
        If vsoTargetShape.Master.Name Like "*Process*" Or vsoTargetShape.Master.Name Like "*Rectangle*" Then
            ' 在流程框右上角创建深蓝色圆形图标
            Set vsoNotificationIcon = vsoPage.DrawOval( _
                vsoTargetShape.Cells("PinX").ResultIU + vsoTargetShape.Cells("Width").ResultIU / 2 + borderOffset, _
                vsoTargetShape.Cells("PinY").ResultIU + vsoTargetShape.Cells("Height").ResultIU / 2 + borderOffset, _
                vsoTargetShape.Cells("PinX").ResultIU + vsoTargetShape.Cells("Width").ResultIU / 2 + borderOffset + iconSize, _
                vsoTargetShape.Cells("PinY").ResultIU + vsoTargetShape.Cells("Height").ResultIU / 2 + borderOffset + iconSize)
            
            ' 设置图标样式与文本
            With vsoNotificationIcon
                ' 填充深蓝色
                .CellsU("FillForegnd").FormulaU = "RGB(0,51,102)"
                .CellsU("FillPattern").FormulaU = "1" ' 实心填充
                ' 隐藏边框
                .CellsU("LineWeight").FormulaU = "0"
                
                ' 获取并设置编号文本
                inputNumber = InputBox("输入图标编号(如3.1、3.12):", "设置编号", "3.1")
                If inputNumber <> "" Then
                    .Text = inputNumber
                    ' 文本样式:白色、居中、小号字体
                    .CellsU("Char.Color").FormulaU = "RGB(255,255,255)"
                    .CellsU("Para.HorzAlign").FormulaU = "2"
                    .CellsU("Char.Size").FormulaU = "8"
                End If
                
                ' 将图标绑定为流程框的子形状,随父形状同步变动
                .MoveToContainer vsoTargetShape, visContainerFitNone
                ' 固定图标在父框右上角的相对位置
                .CellsU("PinX").FormulaU = vsoTargetShape.Name & "!PinX + " & vsoTargetShape.Name & "!Width*0.5 + " & borderOffset
                .CellsU("PinY").FormulaU = vsoTargetShape.Name & "!PinY + " & vsoTargetShape.Name & "!Height*0.5 + " & borderOffset
            End With
        End If
    Next vsoTargetShape
End Sub

使用步骤

  1. 打开Visio,按Alt+F11打开VBA编辑器
  2. 插入新模块,粘贴上述代码
  3. 在Visio画布中选中需要添加图标的流程框
  4. 运行宏AddCustomNotificationIcon,按提示输入编号即可

扩展优化提示

  • 调整图标位置:修改代码中PinX/PinY的公式,可将图标移至左下角、左上角等位置
  • 批量预设编号:可替换输入框为下拉选择菜单,快速选择常用编号
  • 统一样式管理:将图标样式封装为独立函数,方便后续统一修改颜色、尺寸

内容的提问来源于stack exchange,提问作者emmie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 21:32:12