vb 操作excel, 假设excel的一个格子文本为: "AAABBB", 现在要让AAA的字体颜色为蓝色,BBB的颜色是红色。

这样不知道要怎么写vb代码。。
2025-05-17 02:44:59
推荐回答(1个)
回答1:

假设在a1
Range("a1").Select

With ActiveCell.Characters(Start:=1, Length:=3).Font
.Name = "仿宋_GB2312"
.FontStyle = "常规"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 27
End With

With ActiveCell.Characters(Start:=4, Length:=3).Font
.Name = "仿宋_GB2312"
.FontStyle = "常规"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 3
End With