excel - 是否可以使用自定义颜色来使用 VBA 填充单元格?
问题描述
我正在使用颜色索引 20 来填充一些单元格,但这不是我对这个项目的首选颜色。我会使用不在颜色索引调色板中的自定义浅灰色。是否可以?
这是我的代码:
Sheets("Panel").Range("E7:E31").Interior.ColorIndex = 20
解决方案
单元格颜色选择器
- 您可以将所需的颜色应用于单元格并运行以下程序,选择单元格并按ENTER或选择
OK
,颜色值将复制到剪贴板,等待您使用CTRL+ V。
编码
Option Explicit
Sub CellColorPicker()
Dim rgAddress As String
If TypeName(Selection) = "Range" Then
rgAddress = Selection.Cells(1).Address
Else
rgAddress = "A1"
End If
Dim rg As Range
On Error Resume Next
Set rg = Application.InputBox("Pick a cell", "ColorPicker", _
rgAddress, , , , , 8)
On Error GoTo 0
If Not rg Is Nothing Then
With CreateObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
.SetText rg.Cells(1).Interior.Color
.PutInClipboard
End With
End If
End Sub
推荐阅读
- sql-server - 选择前 12 小时窗口中的记录
- angular - 什么是
- python - Python - 为 csv/xls 文件生成 avro 模式
- ubuntu - 即使 After= 服务未启动,Systemd 目标文件也会启动
- r - R按一列分组并将自定义功能应用于另一列
- ios - Swift:在 NWConnection 类中,何时调用 receiveMessage(completion:)
- java - 如何使用 Selenium 和 Serenity 在特定 css 中获取菜单项
- javascript - 通过href从其他页面遍历时调用javascript保留过滤器状态
- python - 如何在使用 PIL 保存 png 时保留 RGB 颜色?
- c# - Sql server 未在 Visual Studio 中加载