字体颜色变成白色而不是灰色
我仍然在学习如何编写代码,但是我只是不明白为什么我没有做这么简单的任务,而我已经做了很多次了。
该代码应该将字体颜色更改为灰色,但它会更改为白色。
For j = 1 To 12 With wsTank.Cells(first(i), j) .Value = "NIL" With .Font .ThemeColor = xlThemeColorDark1 .TintAndShade = -0.499984740745262 End With With .Interior .Pattern = xlNone .TintAndShade = 0 .PatternTintAndShade = 0 End With With .Borders(xlEdgeTop) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlHairline End With With .Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = xlAutomatic .TintAndShade = 0 .Weight = xlHairline End With End With Next j
我在网上搜了很多,发现一个有类似问题的人:
https://www.experts-exchange.com/questions/26937588/Excel-vba-font-color-keeps-shoeing-white-instead-of-gray.html
经过几次愿意帮助的人的尝试之后,他明白了。
但我只是不明白他的解释,所以我没有成功应用于我的案子。
有人请赐教吗?
(这个问题发生在Excel 2010中。在Excel 2013中,代码工作得很好)
链接中的答案是根本不使用Themecolor
,而是使用Color
来代替RGB值:
With .Font .Color = &H808080 .TintAndShade = 0 end with
这应该适用于任何版本的Excel。
.Font.Color = RGB(255, 255, 255)
xl...
语句xl...
更改时可能会有所不同。