![]() |
#2
blueheartghz2013-04-02 11:42
|

Private Sub Command1_Click()
Dim strconn As String
Dim stremp As String
Dim cn As New ADODB.Connection
Dim cnn As New ADODB.Connection
stremp = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=test;PWD=test;Initial Catalog=Progam_Data;Data Source=localhost"
strconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Temp\temp.xls;Extended Properties=Excel 8.0"
cn.Open strconn
cnn.Open stremp
Set rstschema = cn.OpenSchema(adSchemaTables)
Do Until rstschema.EOF
strsql = "insert into" & strtemp & " TEST_N select * from[" & rstschema!TABLE_NAME & "]"
cn.Execute strsql, Ingrecsaff, adExecuteNoRecords
rstschema.MoveNext
Loop
End Sub
问题:1、如果事先不打开E:\Temp\temp.xls文件,会报错“外部表不是预期的格式。”
2、事先打开E:\Temp\temp.xls文件,在红色代码处会出现“Microsoft Jet数据库引擎找不到对象'TEST_N'。”其中TEST_N是想要导入的目标表格。
谢谢大家啊~~
