我正在研究VBA项目,我需要的一项功能是扫描图片以获取特定的RGB颜色,然后自动在该像素上单击鼠标。我一直坚持自动扫描像素(例如,搜索红色#ff0000)。
有人有什么想法吗?
您可以尝试使用此代码:
'Ensure cell has a fill color
If cell.Interior.ColorIndex <> xlNone Then
'Get Hex values (values come through in reverse of what we need)
FillHexColor = Right("000000" & Hex(cell.Interior.Color), 6)
'Reverse the Hex code
FillHexColor = Right(FillHexColor, 2) & Mid(FillHexColor, 3, 2) & Left(FillHexColor, 2)
'Add # sign and display in cell to the right
cell.Offset(0, 1).Value = "#" & FillHexColor
End If
链接到完整代码HERE
但是我认为检查颜色值而不是十六进制值的更好方法。
有关更多信息,请查看HERE