|
两个问题:
都是在SQL语句出的问题
1、按照下列程序走,SHEET7表格汇总A1单元格返回值是F1.
2、如果把SQL语句中的SHEET1改成SHEET2,系统提示Microsoft access数据库引擎找不到对象sheet2$a:g.
请大神给看看。谢谢啦。
Sub CopyData_5()
With Sheet7
.Cells.Clear
Set Cnn = CreateObject("ADODB.Connection")
With Cnn
.Provider = "microsoft.Ace.oledb.12.0"
.ConnectionString = "Extended Properties=Excel 12.0;" _
& "Data Source=" & ThisWorkbook.FullName
.Open
End With
Set rs = CreateObject("ADODB.Recordset")
Sql = "select * from [Sheet1$a:g]"
Set rs = Cnn.Execute(Sql)
For i = 0 To rs.Fields.Count - 1
Cells(1, i + 1) = rs.Fields(i).Name
Next
Range("a2").CopyFromRecordset rs
End With
rs.Close
Cnn.Close
Set rs = Nothing
Set Cnn = Nothing
End Sub
|
|