EXCEL セルの色を取得する関数

セルの色を取得する関数

 

Option Explicit

 

Function ColorIndex(ByVal DataCell As Range) As Integer

Application.Volatile
ColorIndex = DataCell.Interior.ColorIndex

End Function

Function Color(ByVal DataCell As Range) As Long

Application.Volatile
Color = DataCell.Interior.Color

End Function

Function ColorRGB(ByVal DataCell As Range) As String

Application.Volatile
' ColorRGB = Right$("00000" & Hex(DataCell.Interior.color), 6)
ColorRGB = "RGB(" & Val("&H" & Right$("00" & Hex(DataCell.Interior.color), 2)) & ", " _
           & Val("&H" & Left$(Right$("0000" & Hex(DataCell.Interior.color), 4), 2)) & ", " _
           & Val("&H" & Left$(Right$("00000" & Hex(DataCell.Interior.color), 6), 2)) & ")"

End Function

  

以上。