Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA:颜色不对_Excel_Vba_Colors - Fatal编程技术网

Excel VBA:颜色不对

Excel VBA:颜色不对,excel,vba,colors,Excel,Vba,Colors,我想在HTML文件中使用单元格的背景色。因此,我需要颜色的十六进制代码。我使用以下代码来获取背景色的十六进制代码 MsgBox (ActiveCell.Interior.Color) MsgBox Right("000000" & Hex(ActiveCell.Interior.Color), 6) 第一行返回2303331,第二行返回232563。我在两个不同的网站上尝试将2303331转换为十六进制数。两人的回答都是232563。我还尝试了反向转换,将23256

我想在HTML文件中使用单元格的背景色。因此,我需要颜色的十六进制代码。我使用以下代码来获取背景色的十六进制代码

MsgBox (ActiveCell.Interior.Color)
MsgBox Right("000000" & Hex(ActiveCell.Interior.Color), 6)
第一行返回2303331,第二行返回232563。我在两个不同的网站上尝试将2303331转换为十六进制数。两人的回答都是232563。我还尝试了反向转换,将232563转换为十进制,得到了2303331。所以,数字还可以

然后,我在两个不同的网站上输入了232563,以查看颜色是否与Excel表格上的颜色匹配。不,不匹配。232563是蓝色,而我的颜色是棕色,类似于450000

我不知道如何获取手机背景的十六进制代码

如果您尝试以下方法: 十六进制RGB30、30、50 您将看到答案是321E1E ==>VBA将RGB存储为。。。。BGR

试试632523的颜色-

如果您尝试以下操作: 十六进制RGB30、30、50 您将看到答案是321E1E ==>VBA将RGB存储为。。。。BGR


试试632523的颜色-

必须反转十六进制字符串:

Sub testHexColor()
 Dim hexStringCol As String
  MsgBox (ActiveCell.Interior.Color)
  hexStringCol = Right("000000" & Hex(ActiveCell.Interior.Color), 6)
  Debug.Print hexStringCol
  hexStringCol = "#" & Right(hexStringCol, 2) & Mid(hexStringCol, 3, 2) & left(hexStringCol, 2)
  Debug.Print hexStringCol 'this is the correct one
End Sub
您可以从获取的十六进制字符串中提取RGB并为相邻单元格着色来测试它:

ActiveCell.Offset(0, 1).Interior.Color = HEXCOL2RGB(hexStringCol)
并使用下一个转换函数:

Private Function HEXCOL2RGB(ByVal HexColor As String) As String
 Dim Red As String, Green As String, Blue As String
 HexColor = Replace(HexColor, "#", "")
  Red = val("&H" & Mid(HexColor, 1, 2))
  Green = val("&H" & Mid(HexColor, 3, 2))
  Blue = val("&H" & Mid(HexColor, 5, 2))
  HEXCOL2RGB = RGB(Red, Green, Blue)
End Function

必须反转十六进制字符串:

Sub testHexColor()
 Dim hexStringCol As String
  MsgBox (ActiveCell.Interior.Color)
  hexStringCol = Right("000000" & Hex(ActiveCell.Interior.Color), 6)
  Debug.Print hexStringCol
  hexStringCol = "#" & Right(hexStringCol, 2) & Mid(hexStringCol, 3, 2) & left(hexStringCol, 2)
  Debug.Print hexStringCol 'this is the correct one
End Sub
您可以从获取的十六进制字符串中提取RGB并为相邻单元格着色来测试它:

ActiveCell.Offset(0, 1).Interior.Color = HEXCOL2RGB(hexStringCol)
并使用下一个转换函数:

Private Function HEXCOL2RGB(ByVal HexColor As String) As String
 Dim Red As String, Green As String, Blue As String
 HexColor = Replace(HexColor, "#", "")
  Red = val("&H" & Mid(HexColor, 1, 2))
  Green = val("&H" & Mid(HexColor, 3, 2))
  Blue = val("&H" & Mid(HexColor, 5, 2))
  HEXCOL2RGB = RGB(Red, Green, Blue)
End Function

作为将来的参考,你可以使用这个小的,免费的,实用程序,它会给你所需要的颜色,几乎任何你想要的格式:RGB,VB十六进制,Delphi十六进制,HTML十六进制等


作为将来的参考,你可以使用这个小的,免费的,实用程序,它会给你所需要的颜色,几乎任何你想要的格式:RGB,VB十六进制,Delphi十六进制,HTML十六进制等