如何使用VBA使Excel 2007中的单元格透明

16

我目前拥有:

Range("Z1").Interior.Color = RGB(255, 255, 255)

但是这样会清除单元格的边框。相反,我只想将范围内单元格的透明度设置为1.0。文档似乎表明它不存在(?)。
谢谢!
3个回答

39

Range("Z1").Interior.ColorIndex = xlNone


1
非常好。非常感谢。您能告诉我这个知识的参考资料吗?MSDN似乎没有立即可用的:ColorIndex没有提到透明度。此页面列出了x1None,但没有描述(?!grr)。有趣的是,它还列出了xlTransparent,它具有不同的值(毫不奇怪)不起作用。无论如何,非常感谢您的帮助! - AJP
3
使用 xlNone 和在 Excel 菜单中选择“无填充”是相同的,它并不是真正的“透明”。从技术上讲,可能应该使用 xlColorIndexNone,但它们具有相同的值...... ColorIndex 属性也适用于其他对象,如字体和边框,所以当应用于 Interior.ColorIndex 时,您可能会看到没有效果的值。有时参考最好的方法就是录制一个宏并查看生成的内容。对象浏览器(在 VB 编辑器中按 F2)也很有用。 - Tim Williams
再次感谢Tim,真希望我能给这个更多的分数。录制宏非常成功:Sub Macro1() Range("T1:W4").Select With Selection.Interior .Pattern = xlNone .TintAndShade = 0 .PatternTintAndShade = 0 End With End Sub - AJP

0
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Cells.Count > 1 Then Exit Sub
    Application.ScreenUpdating = False
    ' Clear the color of all the cells
    Cells.Interior.ColorIndex = 0
    With Target
        ' Highlight the entire row and column that contain the active cell
        .EntireRow.Interior.ColorIndex = 8
        .EntireColumn.Interior.ColorIndex = 8
    End With
    Application.ScreenUpdating = True
End Sub

一些解释会很好。 - rayryeng

0

也许一个简单的方法是 (符号).(线条或背景)颜色 = -1 '透明


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接