VB 参数不足期待是1 急求各位高手,在线等
PrivateSubcmdLoad_Click()Dimexcel_appAsObjectDimexcel_sheetAsObjectDimdbAsDatabaseDim...
Private Sub cmdLoad_Click()
Dim excel_app As Object
Dim excel_sheet As Object
Dim db As Database
Dim new_value As String
Dim row As Integer
Screen.MousePointer = vbHourglass
DoEvents
'建立Excel application对象
Set excel_app = CreateObject("Excel.Application")
'打开指定的工作薄
excel_app.Workbooks.Open FileName:=txtExcelFile.Text
'判断版本
If Val(excel_app.Application.Version) >= 8 Then
Set excel_sheet = excel_app.ActiveSheet
Else
Set excel_sheet = excel_app
End If
'打开Access数据库
Set db = OpenDatabase(txtAccessFile.Text)
'删除表中原有记录
db.Execute "delete from TestValues"
' 从Excel工作表中获取数据并插入到数据库的TestValues表中
row = 1
Do
' 得到工作表中的值
new_value = Trim$(excel_sheet.Cells(row, 1))
'如果某行空,则停止
If Len(new_value) = 0 Then Exit Do
'将获取的值插入到数据库的表TestValues中
db.Execute "INSERT INTO TestValues VALUES (" & new_value & ")" <<<<<<<<<<<<<<<<<============出错处!!!
'下一行
row = row + 1
Loop
' 关闭数据库
db.Close
'释放内存
Set db = Nothing
'关闭工作表,不重新保存
excel_app.ActiveWorkbook.Close False
'关闭Excel
excel_app.Quit
'释放内存
Set excel_sheet = Nothing
Set excel_app = Nothing
'鼠标指针形状还原
Screen.MousePointer = vbDefault
'弹出提示框
MsgBox "Copied " & Format$(row - 1) & " values.", , "Finished"
End Sub
这段代码的作用是把EXCEL的数据写入数据库中,我从书上搬到电脑上的,一直报错一直报错,我急用这个功能,请各位高手指点下,谢谢~~
Private Sub Form_Load()
'初始化文件路径
Dim file_path As String
file_path = App.Path
If Right$(file_path, 1) <> "\" Then file_path = file_path & "\"
txtExcelFile.Text = file_path & "XlsToMdb.xls"
txtAccessFile.Text = file_path & "XlsToMdb.mdb"
End Sub
表结构是 部门,职务,姓名,性别,班级,联系方式 。都是text格式。
tq09tm5, 你说的方法我试了试,不行啊。 展开
Dim excel_app As Object
Dim excel_sheet As Object
Dim db As Database
Dim new_value As String
Dim row As Integer
Screen.MousePointer = vbHourglass
DoEvents
'建立Excel application对象
Set excel_app = CreateObject("Excel.Application")
'打开指定的工作薄
excel_app.Workbooks.Open FileName:=txtExcelFile.Text
'判断版本
If Val(excel_app.Application.Version) >= 8 Then
Set excel_sheet = excel_app.ActiveSheet
Else
Set excel_sheet = excel_app
End If
'打开Access数据库
Set db = OpenDatabase(txtAccessFile.Text)
'删除表中原有记录
db.Execute "delete from TestValues"
' 从Excel工作表中获取数据并插入到数据库的TestValues表中
row = 1
Do
' 得到工作表中的值
new_value = Trim$(excel_sheet.Cells(row, 1))
'如果某行空,则停止
If Len(new_value) = 0 Then Exit Do
'将获取的值插入到数据库的表TestValues中
db.Execute "INSERT INTO TestValues VALUES (" & new_value & ")" <<<<<<<<<<<<<<<<<============出错处!!!
'下一行
row = row + 1
Loop
' 关闭数据库
db.Close
'释放内存
Set db = Nothing
'关闭工作表,不重新保存
excel_app.ActiveWorkbook.Close False
'关闭Excel
excel_app.Quit
'释放内存
Set excel_sheet = Nothing
Set excel_app = Nothing
'鼠标指针形状还原
Screen.MousePointer = vbDefault
'弹出提示框
MsgBox "Copied " & Format$(row - 1) & " values.", , "Finished"
End Sub
这段代码的作用是把EXCEL的数据写入数据库中,我从书上搬到电脑上的,一直报错一直报错,我急用这个功能,请各位高手指点下,谢谢~~
Private Sub Form_Load()
'初始化文件路径
Dim file_path As String
file_path = App.Path
If Right$(file_path, 1) <> "\" Then file_path = file_path & "\"
txtExcelFile.Text = file_path & "XlsToMdb.xls"
txtAccessFile.Text = file_path & "XlsToMdb.mdb"
End Sub
表结构是 部门,职务,姓名,性别,班级,联系方式 。都是text格式。
tq09tm5, 你说的方法我试了试,不行啊。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询