我用office003运行以下程序正常,但在win7 64位的office2010上运行,提示运行时错误,至少缺一个参数。
我反复检查调整了SQL语句,都没法解决。请高手指点。万分感谢!
Sub 分类汇总()
Dim word As String
If Application.Version = "14.0" Then
      word = "Microsoft.ACE.OLEDB.12.0;extended properties='excel 12.0;hdr=no;IMEX=1';data source="   '对应office2010  64位OK"
    ElseIf Application.Version = "11.0" Then
      word = "microsoft.jet.oledb.4.0;extended properties=excel 8.0;data source="   '对应office2003 OK
    Else
       MsgBox "不支持这个版本的 Excel,请与管理员联系 "
End If
Range("A2:E100").ClearContents
Set conn = CreateObject("adodb.connection")
conn.Open "provider=" & word &  ThisWorkbook.FullName
sq1 = "select 类别,数量,金额 from [Sheet1$]"
sq2 = "select 类别,数量,金额 from [Sheet2$]"
sq3 = "select 类别,数量,金额 from [Sheet3$]"
sq4 = sq1 & " UNION ALL " & sq2 & " UNION ALL " & sq3
sq5 = "select 类别,SUM(数量),SUM(金额) from (" & sq4 & ") GROUP BY 类别"
[a65536].End(xlUp).Offset(1, 0).CopyFromRecordset conn.Execute(sq5)
conn.Close
Set conn = Nothing
End Sub