|
附件:归档.zip第一个问题:这个是我模仿的一个把Excel中的数据写入到ACCESS中的代码?我执行了之后,虽然没报错,到时没有数据写进ACCESS中,不知道是什么问题?具体见附件模块1
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Sub Excel导入数据进ACCESS() '导入到ACCESS程序中
Dim cnn As Object, rs As Object, SQL$, s$, i As Integer
Set cnn = CreateObject("adodb.connection")
cnn.Open "provider=microsoft.jet.oledb.4.0;data source=" & ThisWorkbook.Path & "\myData(副本).mdb"
Set rs = cnn.Execute("分时数据")
For i = 1 To rs.Fields.Count - 1
s = s & "," & rs.Fields(i).Name ' "s=,Dat,Tim,Stock,Price,Volume,Direction"
Next
SQL = "select " & Mid(s, 2) & " from [Excel 8.0;hdr=no;Database=" & ThisWorkbook.FullName & "].[" & ActiveSheet.Name & "$A2:F" & [a1048567].End(xlUp).Row & "]"
SQL = "insert into 分时数据 select(" & Mid(s, 2) & ")" & SQL
cnn.Execute SQL
rs.Close
cnn.Close
Set rs = noting
Set cnn = noting
End Sub
第二个问题:谁能帮我详细解释一下,下面这段代码成功导入ACCESS的原理,其中“f1 ,f2..."在代码中有什么作用,主要是SQL看不懂什么意思。具体看模块2(经测试可以用)
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Sub Excel导入数据进ACCESS2() '导入到ACCESS程序中
Dim cnn As Object, rs As Object, SQL$, s$, i As Integer
Set cnn = CreateObject("adodb.connection")
cnn.Open "provider=microsoft.jet.oledb.4.0;data source=" & ThisWorkbook.Path & "\myData.mdb"
Set rs = cnn.Execute("分时数据")
For i = 1 To rs.Fields.Count - 1
s = s & ",f" & i & " as " & rs.Fields(i).Name
Next
SQL = "select " & Mid(s, 2) & " from [Excel 8.0;hdr=no;Database=" & ThisWorkbook.FullName & "].[" & ActiveSheet.Name & "$A2:F" & [a1048567].End(xlUp).Row & "]"
SQL = "insert into 分时数据 select * from (" & SQL & ")"
cnn.Execute SQL
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
|
-
-
-
归档.zip
621.37 KB, 下载次数: 17
一个EXCEL和ACCESS文件
|