|
将ACCESS中的数据导出到EXCEL后,需要格式化导出的数据,只是在红字处,出现了错误,不知道怎么改了。请帮忙看看,该怎么改动。谢谢!
Sql = "SELECT * from 表"
rs.Open Sql, mydb, adOpenStatic, adLockReadOnly
If rs.EOF = False Then
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Add
xlApp.Visible = True
With xlApp
For n1 = 0 To rs.Fields.Count - 1
Set fld = rs.Fields(n1)
xlApp.Cells(2, n1 + 1) = fld.Name
Next
.Range("a3").CopyFromRecordset rs
Set rng = .Sheets("sheet1").Range("a1").CurrentRegion
sAddress = rng.Address(0, 0)
If rs.State = 1 Then rs.Close
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" & ThisWorkbook.FullName '''ThisWorkbook.FullName出现问题了
Sql = "TRANSFORM sum(数量) SELECT 字段1,字段2 FROM [sheet1$ & " & sAddress & "] GROUP BY 字段1,字段2 PIVOT 字段1" '''sheet1$这里也有错误
rs.Open (Sql), cnn, adOpenKeyset, adLockReadOnly
end with
|
|