Here is a script that reads columns 1 and 2 from an open Excel spreadsheet and places the information in the string variable szText (you might want to change the second dderequest command to use a different variable if you'll need to access both pieces of information at the same time). The script reads from the spreadsheet until the string exit is found in column 1 of the row being accessed.
proc main
long LinkVar, SystemVar ; Variables containing DDE Id's.
string szText ; Text read from DDE link to Excel.
integer iRow, iCol1, iCol2 ; Row and column variables
string sRowCol ; Holds request for row and column
iCol1 = 1 ; Initialize variables
iCol2 = 2
iRow = 1
; Set up DDE links to Excel's system and a spreadsheet. Excel
; must be running in order for this script to work properly.
if ddeinit SystemVar "excel" "system"
ddeexecute SystemVar "[FULL(TRUE)]" ; Maximize the spreadsheet.
if ddeinit LinkVar "excel" "sheet1" ; Set up link to spreadsheet.
while 1 ; Loop forever.
strfmt sRowCol "R%dC%d" iRow iCol1
dderequest LinkVar sRowCol szText ; Read data from spreadsheet, current row, column 1
if stricmp szText "exit`r`n"
exitwhile ; Exit the while loop.
else
strfmt sRowCol "R%dC%d" iRow iCol2
dderequest LinkVar sRowCol szText ; Read data from spreadsheet, current row, column 2
endif
iRow++ ; Increment row value
endwhile
ddeterminate LinkVar ; Break DDE link to spreadsheet.
ddeterminate SystemVar ; Break DDE link to Excel.
else
errormsg "Couldn't establish DDE link to spreadsheet!"
endif
else
errormsg "Couldn't establish DDE link to Excel!"
endif
endproc
aspect@aspectscripting.com