VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   10230
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   12240
   LinkTopic       =   "Form1"
   ScaleHeight     =   10230
   ScaleWidth      =   12240
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox Text1 
      Height          =   615
      Left            =   840
      TabIndex        =   2
      Text            =   "Enter path of colour patch"
      Top             =   9360
      Width           =   8895
   End
   Begin VB.PictureBox Picture1 
      Height          =   8295
      Left            =   120
      ScaleHeight     =   8235
      ScaleWidth      =   11835
      TabIndex        =   1
      Top             =   120
      Width           =   11895
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Get RGB Values!"
      Height          =   615
      Left            =   840
      TabIndex        =   0
      Top             =   8520
      Width           =   8895
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Type RGB
r As Byte
g As Byte
b As Byte
hdc As Byte
End Type

Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long

Private Function GetRGB(lColor As Long) As RGB
Dim tmpVar As RGB
tmpVar.r = lColor Mod &H100
tmpVar.g = (lColor \ &H100) Mod &H100
tmpVar.b = ((lColor \ &H10000)) Mod &H100
GetRGB = tmpVar
End Function

Private Sub Command1_Click()

Dim filePath As String
filePath = Text1.Text
Picture1.Picture = LoadPicture(filePath)

Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWS As Excel.Worksheet

Set xlApp = New Excel.Application
Set xlWB = xlApp.Workbooks.Add
Set xlWS = xlWB.Worksheets.Add
xlApp.Workbooks.Open ("C:\temp\mysheet.xls")

Dim rgbVals As RGB
rgbVals = GetRGB(GetPixel(Picture1.hdc, 242, 191)) 'Choose your own X,Y
xlWS.Cells(1, 2).Value = (rgbVals.r)
xlWS.Cells(1, 3).Value = (rgbVals.g)
xlWS.Cells(1, 4).Value = (rgbVals.b)

xlWS.SaveAs "C:\temp\mysheet1.xls"
xlApp.Quit

'MsgBox "Red = " & rgbVals.r & vbCrLf & "Green = " & rgbVals.g & vbCrLf & "Blue = " & rgbVals.b





End Sub
