Option Explicit #If VBA7 Then Private Declare PtrSafe Function CreateDCW Lib "gdi32" (ByVal pwszDriver As LongPtr, ByVal pwszDevice As LongPtr, ByVal pszPort As LongPtr) As LongPtr Private Declare PtrSafe Function DeleteDC Lib "gdi32" (ByVal hDC As LongPtr) As Long Private Declare PtrSafe Function GetPixel Lib "gdi32" (ByVal hDC As LongPtr, ByVal nXPos As Long, ByVal nYPos As Long) As OLE_COLOR #Else Private Declare PtrSafe Function CreateDCW Lib "gdi32" (ByVal pwszDriver As OLE_HANDLE, ByVal pwszDevice As OLE_HANDLE, ByVal pszPort As OLE_HANDLE) As OLE_HANDLE Private Declare PtrSafe Function DeleteDC Lib "gdi32" (ByVal hDC As OLE_HANDLE) As Long Private Declare PtrSafe Function GetPixel Lib "gdi32" (ByVal hDC As OLE_HANDLE, ByVal nXPos As Long, ByVal nYPos As Long) As OLE_COLOR #End If Public Function GetColor(x&, y&) As OLE_COLOR #If VBA7 Then Dim hDC As LongPtr hDC = CreateDCW(StrPtr("DISPLAY"), 0, 0) #Else Dim hDC As OLE_HANDLE hDC = CreateDCW(ByVal StrPtr("DISPLAY"), ByVal 0&, ByVal 0&) #End If If GetColor = GetPixel(hDC, x, y) DeleteDC hDC End Function