Vba vb查找最近的已知颜色

Vba vb查找最近的已知颜色,vba,colors,Vba,Colors,我一直在寻找最近的已知颜色,比如 dim nearestcolor as color= bitmap.getpixel(point.x,point.y) if nearestcolor.toknowncolor = color.red then end if 我需要类似的东西,我需要找到最接近的颜色是否看起来像红色,不确定这是否是你的答案,但你可以把颜色的rgb值想象为x、y、z平面上的点,并使用几何计算已知颜色和像素颜色之间的距离 ?VB.NET?看起来不像VBA。 Sub HoldCo

我一直在寻找最近的已知颜色,比如

dim nearestcolor as color= bitmap.getpixel(point.x,point.y)
if nearestcolor.toknowncolor = color.red then 

end if

我需要类似的东西,我需要找到最接近的颜色是否看起来像红色,不确定这是否是你的答案,但你可以把颜色的rgb值想象为x、y、z平面上的点,并使用几何计算已知颜色和像素颜色之间的距离

?VB.NET?看起来不像VBA。
Sub HoldCol()
    Dim colC, CC&
' all thanks to Mr Chip Pearson
    colC = Array("UNNAMED", _
                 "Black", "White", "Red", "Bright Green", "Blue", "Yellow", "Pink", "Turquoise", _
                 "Dark Red", "Green", "Dark Blue", "Dark Yellow", "Violet", "Teal", "Gray 25%", "Gray 50%", _
                 "UNNAMED", "UNNAMED", "UNNAMED", "UNNAMED", "UNNAMED", "UNNAMED", "UNNAMED", "UNNAMED", _
                 "Dark Blue", "Pink", "Yellow", "Turquoise", "Violet", "Dark Red", "Teal", "Blue", _
                 "Sky Blue", "Light Turquoise", "Light Green", "Light Yellow", "Pale Blue", "Rose", "Lavender", "Tan", _
                 "Light Blue", "Aqua", "Lime", "Gold", "Light Orange", "Orange", "Blue Gray", "Gray 40%", _
                 "Dark Teal", "Sea Green", "Dark Green", "Olive Green", "Brown", "Plum", "Indigo", "Gray 80%")
    'cc  as collor to look at
    ' or use fill color to color cell

    CC = [m4].Interior.Color

    [m5].Interior.Color = CC    '[m4]  ' put color in cell   'out of need
    [m6] = [m5].Interior.ColorIndex    ' let vba find the nearest color index
    [n6] = CStr(colC([m6]))    ' get its name
    [m7].Interior.ColorIndex = [m6]
    ' may be offset 1 if you are using option base 1
    ' gets only close as you can see in cell "M7"
'use variable names   in reality

End Sub