WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Excel
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

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

Article ID:   W15643
File Created: 2003:05:13:11:29:20
Last Updated: 2003:05:13:11:29:20