====================================================================
Ruby wrapper for Excel OLE calls:
Generated by calling the script src\ruby-1.8.6-p111\ext\win32ole\sample\excel.rb
as follows:

ruby olegen.rb 'Microsoft Excel 11.0 Object Library' >excel_app_11.rb

It can then be invoked as follows:
require 'win32ole'
require 'excel_app_11'
raw_excel = WIN32OLE.connect("excel.application")
@excel = Excel_Application_11.new(raw_excel)

This @excel object will accept all the same messages as the raw one.
The documentation suggests that this will be faster; benchmarking
has too much variance to be able to tell.

Some warning messages about redefined methods show up when
excel_app_11 is loaded.
====================================================================
Connecting to an active Excel worksheet:

require 'win32ole' # need this to use OLE
excel = WIN32OLE.connect("excel.application") # connects to an already running Excel
excel.workbooks.each{|wb|puts wb.name} # works for irb: list the open workbooks
input_sheet = excel.activeworkbook.activesheet # create an object for the currently active worksheet
input_sheet.range("a1").value = "Ruby did this" # change the value in cell A1

==========================================================
Public Const SEE_MASK_NOCLOSEPROCESS = &H40
Public Const SEE_MASK_INVOKEIDLIST = &HC
Public Const SEE_MASK_FLAG_NO_UI = &H400
Public Const INFINITE = &HFFFF      'Infinite Wait Time
Public Const SW_NORMAL = 1

Public Type SHELLEXECUTEINFO
        cbSize As Long
        fMask As Long
        hwnd As Long
        lpVerb As String
        lpFile As String
        lpParameters As String
        lpDirectory As String
        nShow As Long
        hInstApp As Long
        '  Optional Fields
        lpIDList As Long
        lpClass As String
        hkeyClass As Long
        dwHotKey As Long
        hIcon As Long
        hProcess As Long
End Type

Public Declare Function ShellExecuteEx Lib "shell32.dll" (SEI As SHELLEXECUTEINFO) As Long
Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public Sub ExecAndWait(ByVal hwnd As Long, ByVal ProgramPath As String)
Dim SEI As SHELLEXECUTEINFO
'Filling SEI structure
With SEI
    .cbSize = Len(SEI)     'Bytes of the structure
    .fMask = SEE_MASK_NOCLOSEPROCESS     'I need hProcess to be retrieved
    .lpFile = ProgramPath 'Program Path
    .lpVerb = "Open"   'Action to do
    .nShow = SW_NORMAL    'How the program will be showed
    .lpDirectory = Left(ProgramPath, (InStrRev(ProgramPath, "\")) - 1)
    .hwnd = hwnd   'Window Handle
End With
ShellExecuteEx SEI         'Execute the program hProcess recives the Process Handle used next.
WaitForSingleObject SEI.hProcess, INFINITE     'Here wait until close the program
CloseHandle hProcess
End Sub

====================================================================
