gpt4 book ai didi

excel - font.TintAndShade 无法更改文本的亮度

转载 作者:行者123 更新时间:2023-12-02 07:28:25 25 4
gpt4 key购买 nike

我选择一个文本并更改其颜色,它告诉我这一点

Range("A7").Select
With Selection.Font
.ThemeColor = xlThemeColorAccent2
.TintAndShade = -1
End With

但是当我运行此代码时,TintAndShade 无法工作。单元格中文本的亮度不能由 vba 指定。有没有其他方法可以改变文本的亮度?或者我怎样才能使 TintAndShade 工作?

最佳答案

我相信您使用的是 Excel 2010。不幸的是,这是 Excel 2010 中的一个错误。不确定它是否已在 Excel 2013 中得到纠正。

这是一个替代方案。创建一个新工作簿并将此代码粘贴到模块中。

逻辑:.TintAndShade 适用于单元格的 .Interior,因此我们将使用它来代替 .TintAndShade code> 单元格的字体。

代码:

Sub Sample()
Dim ws As Worksheet
Dim i As Long

Set ws = ThisWorkbook.Sheets("Sheet1")

With ws
.Range("B1:B256").Value = "Blah Blah"

For i = 1 To 256
.Range("A" & i).Interior.ThemeColor = xlThemeColorAccent2
.Range("A" & i).Interior.TintAndShade = (i * 2 - 256) / 256

.Range("B" & i).Font.Color = .Range("A" & i).Interior.Color
Next i
End With
End Sub

屏幕截图:

当您运行此命令时,您将看到字体亮度的变化,如下面的屏幕截图所示。 :)

enter image description here

注意:

对于实时场景,创建一个临时表,并在任何单元格中将其设置为.Interior.TintAndShade,然后使用它来设置相关单元格的字体亮度,完成后,只需删除临时表即可片材。

关于excel - font.TintAndShade 无法更改文本的亮度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20963435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com