; Define an Excel object pointer
$oXL = xlInstantiateApp()
; Open the file
xlFile($oXL, 0, 'C:\Bin\Book1.xls')
; Return an array of 4 values from the first data row
; Start with row 2, since row 1 has titles
; keep reading until a blank row is returned
$Row = 2
While $Row > 0
$Range = 'A' + CStr($Row) + 'D' + CStr($Row)
$aData = xlRangeValue($oXL, $Range, , 'Sheet1')
; The first element of the array contains the user, fourth has the manager
; Howard Bullok has a great Hash UDF that would work well here, but
; I'm going to use a "poor-man's" hash - an INI file, and reduce the number
; of UDFs required
If $aData[0] = ''
; Anti-Golf to make it clear what data goes where
$User = $aData[0]
$Manager = $aData[3]
$Record = Join($aData, Chr(31)) ; Chr(31) is ASCII US - Unit Separator
$ = WriteProfileString('.\hash.ini', $Manager, $User, $Record)
Else
$Row = -1 ; no more data - exit the loop
EndIf
$Row = $Row + 1
Loop
Function xlFile($_ID, $_FN, $_File)
Dim $_
Select
Case $_FN = 0 ; Open
If Exist($_File) ; if the file exists, open it
;$_ = $_ID.Open($_File, $_Links, $_RO, $_Fmt)
$_ = $_ID.WorkBooks.Open($_File)
Exit @ERROR
Else
Exit 2 ; otherwise complain that is isn't found
EndIf
Case $_FN = 1 ; Save(as)
; If the file was previously saved (or opened), just re-save it,
; otherwise do a Save As
If Not $_ID.ActiveWorkbook.Path
$_ = $_ID.ActiveWorkbook.SaveAs($_File)
Else
$_ = $_ID.ActiveWorkbook.Save
EndIf
Exit @ERROR
Case $_FN = 2 ; SaveAs
$_ = $_ID.ActiveWorkbook.SaveAs($_File)
Exit @ERROR
EndFunction
Function xlRangeValue($_ID, $_Range, OPTIONAL $_Value, OPTIONAL $_Sheet)
$_Sheet = IIf($_Sheet = '', $_ID.ActiveSheet.Name, $_Sheet)
If VarType($_Value) <> 0
$_ID.WorkSheets($_Sheet).Range($_Range).Value = $_Value
Else
$xlRangeValue = $_ID.WorkSheets($_Sheet).Range($_Range).Value
EndIf
Exit @ERROR
EndFunction