如何在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
相关产品推荐
相关产品推荐

