|
关于Excel中的ADO部分,我曾写过一个例子,你先参考下:
http://www.office-cn.net/thread-96398-1-1.html
以下代码在Access中执行(俺{:soso_e147:},该{:soso__4963104980311759478_2:}了,因此代码暂未测试,请自行测试后再告知问题的所在,最好传上附件)。- Private Sub Command2_Click()
- Dim rst2 As New ADODB.Recordset
- dim rst1 As New ADODB.Recordset
- Dim cnn1 As New ADODB.Connection
- Dim st As String
- cnn1.Open "provider=microsoft.jet.oledb.4.0;extended properties= excel 8.0;data source=C:\Users\wangcheng\Documents\exceld导入测试\导入资料.xls"
- '如果SQL过于复杂,则建议使用别名处理。例如Select A.A1 from [Sheet1$A3:D100] As A"。
- rst1.Open "Select * from [Sheet1$A3:D100]",cnn1,adOpenDynamic, adLockOptimistic
- rst2.Open "测试表",CurrentProject.Connection,adOpenDynamic, adLockOptimistic
- Do until rst1.EOF
- rst2.AddNew
- rst2(0)=rst1(0)
- ………………
- rst2.Update
- Loop
- rst1.Close
- Set rst1=Nothing
- cnn1.Close
- Set rst1=Nothing
- rst2.Close
- Set rst2=Nothing
- End Sub
复制代码 不过这样导入数据稍嫌麻烦。。。 |
|