假设这个excel在桌面上,名字为1.xlsx,数据在a列。编写如下程序 private sub command1_click() dim xlapp as excel.application dim xlbook as excel.workbook dim xlsht as excel.worksheet dim i%, r% set xlapp = new excel.application xlapp.visible = true set xlbook = xlapp.workbooks.open("c:\documents and settings\admin\桌面\1.xlsx") set xlsht = xlbook.worksheets(1) r = xlsht.[a65536].end(xlup).row for i = 1 to r if cells(i, 1) < val(text1) or cells(i, 1) > val(text2) then cells(i, 1) = application.worksheetfunction.average(val(text1), val(text2)) else end if next end sub我把1.xls放d盘了,文件名根据你的自己改,另外工程要引入Microsoft Excel xx.0 Object Library以下是代码:Dim xlsApp As Excel.ApplicationDim xlsWorkbook As Excel.WorkbookDim xlssheet As Excel.WorksheetPrivate Sub Command1_Click() Dim temp As String Dim rowNum As Integer rowNum = 1 temp = xlssheet.Cells(rowNum, 1).Value While temp <> "" If temp = Text1.Text Then Label1.Caption = xlssheet.Cells(rowNum, 2).Value Exit Sub End If rowNum = rowNum + 1 temp = xlssheet.Cells(rowNum, 1).Value Wend Label1.Caption = "没有找到"End SubPrivate Sub Form_Load() Set xlsApp = CreateObject("Excel.Application") Set xlsWorkbook = xlsApp.Workbooks.Open("D:\1.xls") xlsApp.DisplayAlerts = False Set xlssheet = xlsWorkbook.Sheets(1)End SubPrivate Sub Form_Unload(Cancel As Integer) xlsWorkbook.Close Set xlssheet = Nothing Set xlsWorkbook = Nothing Set xlsApp = NothingEnd SubDim Excelapp As Excel.Application Set Excelapp = New Excel.Applicationi=1do while Excelapp.ActiveSheet.Cells(1, i) <>"" if Excelapp.ActiveSheet.Cells(1, i) =text1.text then label1.caption= Excelapp.ActiveSheet.Cells(2, i) i=i+1loop