查找Excel表A列里的数据并显示找到的同行B列的内容?帮忙看下哪里出问题了
Dim xlApp As Excel.Application '定义EXCEL类Dim xlBook As Excel.Workbook '定义工件簿类
Dim xlsheet As Excel.Worksheet '定义工作表类
Dim a
Dim aa
Dim bb
Private Sub Command1_Click()
Dim fileadd As String
CommonDialog1.ShowOpen
CommonDialog1.Filter = "xls文件(*.xls)|*.xls" '选择你要的文件
a = CommonDialog1.FileName
Text1.Text = a
If a = "" Then Exit Sub
Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象
Set xlBook = xlApp.Workbooks.Open(a) '打开已经存在的EXCEL工件簿文件
xlApp.Visible = False ' = True '设置EXCEL对象可见(或不可见)
Set xlsheet = xlBook.Worksheets(1) '设置活动工作表
xlApp.DisplayAlerts = False '不进行安全提示 '
End Sub
Private Sub Command2_Click()
xlApp.Quit
Set Xlssheet = Nothing
Set Xlsbook = Nothing
Set Xls = Nothing
err:
Text1.Text = "" '清空内容
Text2.Text = "" '清空内容
Text3.Text = "" '清空内容
End Sub
Private Sub Command3_Click()
With xlsheet
aa = Text2.Text
On Error Resume Next
bb = xlApp.WorksheetFunction.VLookup(aa, Range("A:A"), 3, False)
Text3.Text = bb
If err <> 0 Then MsgBox "你输入的不存在或错误,请查正后重新输入!", vbOKCancel, "输入检查"
On Error GoTo 0
End With
End Sub