Excel返回或设置边框、字体或内部颜色

0表示无色

ColorIndex 属性 (Excel Graph)

返回或设置边框、字体或内部颜色,如中下表所示。 颜色可指定为当前调色板中颜色的索引值,也可指定为下列 XlColorIndex 常量之一:xlColorIndexAutomaticxlColorIndexNone 。 读/写 Variant

语法

expression .ColorIndex

表达式是必需的。 返回"应用于"列表中的一个对象的表达式。

注释

Object 说明
Border 边框的颜色。
Font 字体颜色。
Interior 填充的内部颜色。 将 ColorIndex 设置为 xlColorIndexNone ,以指定你不想进行内部填充。 将 ColorIndex 设置为 xlColorIndexAutomatic,以指定自动填充(适用于图形对象)。

此属性指定一种颜色作为调色板的索引。 下图展示了默认调色板中的颜色索引值。

示例

以下示例假定正在使用默认调色板。

以下示例设置数值轴主要网格线的颜色。

VB

vbscript 复制代码
With myChart.Axes(xlValue) 
 If .HasMajorGridlines Then 
 'Set color to blue 
 .MajorGridlines.Border.ColorIndex = 5 
 End If 
End With

以下示例将图表区内部颜色设置为红色,边框颜色设置为蓝色。

VB

vbscript 复制代码
With myChart.ChartArea 
 .Interior.ColorIndex = 3 
 .Border.ColorIndex = 5 
End With

参考链接

ColorIndex 属性 (Excel Graph) | Microsoft Learnhttps://learn.microsoft.com/zh-cn/office/vba/api/excel.colorindexExcel VBA Interior.ColorIndex 色彩列表 - Alice Sun - 博客园https://www.cnblogs.com/alicesunBlog/articles/2861089.html

特此记录

anlog

2026年5月20日

相关推荐
工具怪4 小时前
Excel 如何加水印?4种常见使用场景与操作步骤
excel
写了20年代码的老程序员1 天前
Excel 导入导出为什么总是把后端逼成字段搬运工
java·excel
Cloud_Shy6181 天前
Python 数据分析基础入门:《Excel Python:飞速搞定数据分析与处理》学习笔记系列(第十一章 Python 包跟踪器 中篇)
数据库·python·sql·数据分析·excel·web
Metaphor6921 天前
使用 Python 将 Excel 转换为 PDF
python·pdf·excel
星越华夏1 天前
Pandas获取excel表sheet名称
excel·pandas
俊哥工具1 天前
不用安装不收费!多功能U盘修复工具,解决大部分U盘故障
学习·pdf·word·excel·音视频
_oP_i1 天前
Excel 工作簿取消保护
excel
程序员杰哥1 天前
Python+requests+excel 接口自动化测试框架
自动化测试·软件测试·python·测试工具·测试用例·excel·接口测试
流形填表2 天前
大风车Excel|本地版软件下载与使用教程(2026最新版)
excel