ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 6973|回复: 2

[求助]用vba 如何取得word的背景颜色呢

[复制链接]

TA的精华主题

TA的得分主题

发表于 2006-4-12 23:19 | 显示全部楼层 |阅读模式
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
rt

TA的精华主题

TA的得分主题

发表于 2006-4-13 12:03 | 显示全部楼层

请测试:

---------------------

Option Explicit

Sub Test()
Dim myColor As Long
myColor = ActiveDocument.Background.Fill.ForeColor.RGB
MsgBox GetColor(myColor)
End Sub
'----------------------
Function GetColor(Color As Long) As String
Select Case Color
Case Is = -16777216
GetColor = "
自动色"
Case Is = 0
GetColor = "
黑色"
Case Is = 13209
GetColor = "
褐色"
Case Is = 13107
GetColor = "
橄榄绿"
Case Is = 13056
GetColor = "
深绿"
Case Is = 6697728
GetColor = "
深灰蓝"
Case Is = 8388608
GetColor = "
深蓝"
Case Is = 10040115
GetColor = "
靛蓝"
Case Is = 3355443
GetColor = "
灰色-80%"
Case Is = 128
GetColor = "
深红"
Case Is = 26367
GetColor = "
桔黄"
Case Is = 32896
GetColor = "
深黄"
Case Is = 32768
GetColor = "
绿色"
Case Is = 8421376
GetColor = "
蓝绿色"
Case Is = 16711680
GetColor = "
蓝色"
Case Is = 10053222
GetColor = "
-"
Case Is = 8421504
GetColor = "
灰色-50%"
Case Is = 255
GetColor = "
红色"
Case Is = 39423
GetColor = "
浅桔黄"
Case Is = 52377
GetColor = "
酸橙色"
Case Is = 6723891
GetColor = "
海绿"
Case Is = 13421619
GetColor = "
宝石蓝"
Case Is = 16737843
GetColor = "
浅蓝"
Case Is = 8388736
GetColor = "
紫色"
Case Is = 10066329
GetColor = "
灰色-40%"
Case Is = 16711935
GetColor = "
粉红"
Case Is = 52479
GetColor = "
金色"
Case Is = 65535
GetColor = "
黄色"
Case Is = 65280
GetColor = "
鲜绿"
Case Is = 16776960
GetColor = "
青绿"
Case Is = 16763904
GetColor = "
天蓝"
Case Is = 6697881
GetColor = "
梅红"
Case Is = 12632256
GetColor = "
灰色"
Case Is = 13408767
GetColor = "
玫瑰红"
Case Is = 10079487
GetColor = "
棕黄"
Case Is = 10092543
GetColor = "
浅黄"
Case Is = 13434828
GetColor = "
浅绿"
Case Is = 16777164
GetColor = "
浅青绿"
Case Is = 16764057
GetColor = "
淡蓝"
Case Is = 16751052
GetColor = "
淡紫"
Case Is = 16777215
GetColor = "
白色"
End Select
End Function
'----------------------

TA的精华主题

TA的得分主题

发表于 2006-4-13 13:03 | 显示全部楼层

Sub 这个行否()
Dim rgb1
rgb1 = ActiveDocument.Background.Fill.ForeColor.RGB
bbb (rgb1)
End Sub
Function bbb(rgb1)
Dim Col As String
Dim R, G, B
Dim dd

'由于出来的是不完整数据,所以在下面做填补
Col = Hex(rgb1)
'判断有多少位,然后保持结果是6位数的
Select Case Len(Col)
Case 6
dd = Col
Case 5
dd = "0" + Col
Case 4
dd = "00" + Col
Case 3
dd = "000" + Col
Case 2
dd = "0000" + Col
Case 1
dd = "00000" + Col
End Select
'16进的颜色格式是 &H BB GG RR,下面提取RGB,然后变回10进
R = CLng("&H" & Right(dd, 2))
G = CLng("&H" & Mid(Left(dd, 4), 3))
B = CLng("&H" & Left(dd, 2))

MsgBox "当前的背景色RGB颜色是:" & R & "," & G & "," & B

End Function

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-18 02:36 , Processed in 0.037822 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表