我想实现将excel里sheet1的数据导入到access数据库dz.mdb里,但运行完后excel进程仍然在后台运行,需要手动结束,各位高手帮忙看看,谢谢各位了。应该是加了粗线部分的原因,导致无法正常结束。
Dim cn As New ADODB.Connection
Dim rs, mrc As New ADODB.Recordset
Dim response
Dim xlApp As EXCEL.Application
Set xlApp = CreateObject("Excel.Application")
Dim xlBook As EXCEL.Workbook
response = MsgBox("导入数据将清空数据库中已经存在的数据,确定要导入新数据吗?", vbOKCancel, "温馨提示")
If response = vbCancel Then
   Exit Sub
End If
dia.DialogTitle = "请选择要导入的excel文件"
dia.Filter = "excel(*.xls) | *.xls"
dia.ShowOpen
If dia.FileName = "" Then
Exit Sub
End If
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & dia.FileName & ";Extended Properties=Excel 8.0;"
Set xlBook = xlApp.Workbooks.Open(dia.FileName)
xlApp.Visible = False
cn.Open
cnn.Open
cnn.Execute ("delete from dz")
Set rs = cn.Execute("select * from [" & xlBook.Sheets(1).Name & "$]")Do While Not rs.EOF
   txtsql = "insert into dz values('" & rs.Fields(0) & "','" & rs.Fields(1) & "','" & rs.Fields(2) & "','" & rs.Fields(3) & "','" & rs.Fields(4) & "',null,'" & rs.Fields(6) & "','" & rs.Fields(7) & "')"
   cnn.Execute (txtsql)
   rs.MoveNextSet rs = Nothing
cnn.Close
cn.Close
Set cnn = Nothing
Set cn = NothingxlBook.Close (dia.FileName)
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing