如何将excel的工作表内容通过VBA代码导入到有密码的access数据库中?
mydb_mdb="F:\mydb.mdb"'确目标数据库TableName="mytable"Sheets(1).ActivateSetconn_excel=NewAD...
mydb_mdb="F:\mydb.mdb" '确目标数据库
TableName="mytable"
Sheets(1).Activate
Set conn_excel = New ADODB.Connection
conn_excel.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;" & _
"Extended Properties=Excel 8.0;" & _
"Data Source=" & ThisWorkbook.Path & "\" & ActiveWorkbook.Name
conn_excel.Open
If conn_excel.State = adStateOpen Then
sSql = "Insert Into [;DataBase=" & mydb_mdb & "]." & TableName & " Select * From [" & ActiveSheet.Name & "$]"
conn_excel.Execute sSql
MsgBox "数据导入成功!"
conn_excel.Close
End If
Set conn_excel = Nothing
假如数据库密码为:123456,请问以上代码该如何修改才能将sheet1的内容导入到数据库中? 展开
TableName="mytable"
Sheets(1).Activate
Set conn_excel = New ADODB.Connection
conn_excel.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0;" & _
"Extended Properties=Excel 8.0;" & _
"Data Source=" & ThisWorkbook.Path & "\" & ActiveWorkbook.Name
conn_excel.Open
If conn_excel.State = adStateOpen Then
sSql = "Insert Into [;DataBase=" & mydb_mdb & "]." & TableName & " Select * From [" & ActiveSheet.Name & "$]"
conn_excel.Execute sSql
MsgBox "数据导入成功!"
conn_excel.Close
End If
Set conn_excel = Nothing
假如数据库密码为:123456,请问以上代码该如何修改才能将sheet1的内容导入到数据库中? 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询