Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Search Excel Spreadsheet

 Keywords:  

Question:

I want to search an excel spreed sheet to see if the computer name exists and if it does then I want it to run a program.

Answer:

This will load an Excel workbook, loop through its worksheets and the rows/cols on each worksheet...
computername = "\\Fred"
;       Start excel here
excelxls = objectopen("Excel.Application")
excelxls.visible = @true
rptxls = excelxls.workbooks
;       specify the workbook to look thru...
excelfile = "D:\Report Stage\sa\temp\CORP1_DTS.xls"
rptxls.open (excelfile)

awb = excelxls.activeworkbook
awbws = awb.worksheets

found = 0
for x = 1 to awbws.count
        currws = awb.worksheets(x)
        currwsname = currws.name
        message("Worksheet", currwsname)
;       on the current worksheet, look thru the first 10 rows of the A column...
        for row = 1 to 10
                col = 1
                actSheet = excelxls.activesheet
                thecell = actSheet.Cells(row,col)
                message("Row %row% Column %col%", thecell.value)
					 if StrUpper(thecell.value) == strUpper(computername	;<<<< Checks for computer name
						 found = 1					 									;<<<<
						 Run("somefile.exe","") 									;<<<<
						 break  															;<<<<
					 endif 																;<<<<
        next
		  if found == 1 then break
next

excelxls.quit
objectclose(excelxls)
exit