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"
CommonDialog1.Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer Or cdlOFNNoDereferenceLinks
CommonDialog1.ShowOpen '打开execl文件作为输入文件
Set xlsApp = CreateObject("Excel.Application") '打开EXECL类型文件
Set xlsBook = xlsApp.Workbooks.Open(CommonDialog1.FileName) '打开已经存在的EXCEL工件簿文件
For k = 1 To xlsBook.Worksheets.Count '处理全部sheet
Set xlSheet = xlsBook.Worksheets(k) '设置当前sheet
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 xlsSheet.Cells(i, j) = "需要查找的内容" Then
msgbox xlsSheet.Cells(i, j)
Exit For
End If
next j
next i
next k
xlsBook.Close (True) '关闭工作簿
xlApp.Quit '结束EXCEL对象
以上代码可以在全部execl中,找到某一个数据并显示,希望有参考
[此贴子已经被作者于2017-3-15 09:04编辑过]