Private Sub command1_Click()
Dim xlsApp As Excel.Application 'EXECL类型文件
Dim xlsBook As Excel.Workbook 'execl工作表
Dim xlsSheet As Excel.Worksheet 'execl sheet
Dim row_tail '行总数
Dim col_total '列总数
commondialog1.Filter = "数据文件(*.xls)|*.xls"'需要引用文件控件,如果不用文件对话方式打开,可以直接给出execl文件名
commondialog1.Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks
commondialog1.ShowOpen '打开execl文件作为输入文件
If commondialog1.FileName <> "" Then
Set xlsApp = CreateObject("Excel.Application") '打开EXECL类型文件
Set xlsBook = xlsApp.Workbooks.Open(commondialog1.FileName) '打开已经存在的EXCEL工件簿文件
Set xlSheet = xlsBook.Worksheets(1) '设置活动工作表
row_tail = xlsSheet.UsedRange.Rows.Count
col_tail = xlsSheet.UsedRange.Columns.Count
For i = 1 To row_tail
For j = 1 To col_tail
If xlSheet.Cells(i, j) = "判断条件" Then
'具体的执行
Exit For
End If
Next j
Next i
xlsBook.Close (True) '关闭工作簿
xlsApp.Quit '结束EXCEL对象
End If
End Sub