|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
先前写了一段SQL,里面有用到临时表,在SQL里正常运行,放到VBA里就报错,把语句精简后还是一样的报错,求各位大神看看精简后的VBA语句如下:
Sub admin()
Dim conn, xRs
Set conn = CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=*****;PWD=*****;Initial Catalog=*****;Data Source=****"
Set xRs = CreateObject("ADODB.RecordSet")
sSql = " SET NOCOUNT ON select * into #test from (SELECT * FROM [A3].[dbo].[info_Employee] ) a select * from #test"
xRs.Open sSql, conn, 1, 3
Sheets("a").Range("A2").CopyFromRecordset xRs
xRs.Close
conn.Close
Set xRs = Nothing
Set conn = Nothing
End Sub
报错信息:
多步OLEDB操作产生错误,如果可能请检查每一OLEDB的状态值,没有工作被完成
|
|