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

如何在Excel VBA代码中设置单元格批注的字体及字号?

Excel VBA批注字体属性设置方案

要给批注设置Courier New字体及字号等属性,需要通过访问批注文本框的Characters.Font对象来修改字体相关属性。在你的现有代码中添加如下代码段即可实现需求:

Sub SetCommants()
With Cells(4, 8)
    If Not .Comment Is Nothing Then .Comment.Delete
    .AddComment
    .Comment.Visible = False
    .Comment.Text Cells(1, 3) & Chr(10) & Cells(1, 4) & Chr(10) & Cells(1, 5) & Chr(10) & Cells(1, 6)
    
    ' 新增:设置批注字体属性
    With .Comment.Shape.TextFrame.Characters.Font
        .Name = "Courier New" ' 指定字体为Courier New
        .Size = 10 ' 设置字号,可按需调整数值
        .Bold = False ' 控制是否加粗,True为加粗,False为常规
        .ColorIndex = 1 ' 设置字体颜色,1对应黑色,可替换为其他颜色索引值
    End With
    
    .Comment.Shape.TextFrame.AutoSize = True
End With 
End Sub

代码说明

  • .Name = "Courier New":强制批注使用Courier New字体
  • .Size = 10:定义字体大小,可根据需求修改为12、14等数值
  • .Bold = False:设置字体粗细,需要加粗时改为True即可
  • .ColorIndex = 1:指定字体颜色,也可以用.Color = RGB(0,0,0)这种方式自定义RGB颜色

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 22:04:51