VB程序员博客
Sub daoyu()
Dim row As Integer
Dim colm As Integer
Dim sheet1 As Object
Dim excel_app As Object
Dim xlsbook As New Excel.Workbook
DoEvents
Set excel_app = CreateObject("excel.application")
excel_app.Workbooks.Open (CommonDialog1.FileName)
Set sheet1 = excel_app.Workbooks(1).Worksheets("sheet1")
ret.CursorLocation = adUseClient
ret.Open sql, conn, adOpenKeyset, adLockPessimistic
fieldsnu = ret.Fields.Count
conn.BeginTrans
row = 2
'Do 'While (Len(Trim$(Sheet.Cells(row, 1))) > 0)
If Len(Trim(Sheet.Cells(row, 1))) = 0 Then
MsgBox "没有数据!", vbOKOnly + vbExclamation, "温馨提示"
ret.AddNew
For colm = 0 To fieldsnu - 1
ret.Fields(colm).Value = Trim(sheet1.Cells(row, colm + 1).Value)
Next colm
ret.Update
row = row + 1
ret.Close
Set ret = Nothing
MsgBox "导入数据成功!", vbOKOnly + vbExclamation, "温馨提示"
conn.CommitTrans
excel_app.ActiveWorkbook.Close
excel_app.Application.Quit
excel_app.Quit
Set sheet1 = Nothing
Set excel_app = Nothing
conn.Close
Set conn = Nothing
End If
End Sub
Private Sub Command1_Click()
sql = "select * from collegedepart"
Call daoyu
End Sub
运行的时候没有响应,急求帮助!!!
在做毕业论文,快要交了,很急呀
ret =ADODB.Recordset ?