|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
我有一个基于SQL的数据透视表,我想通过VBA自动刷新数据透视表里面的数据。但是总是在Refresh这步出错,提示
Run-time error ’1004‘: The connection for viewing your linked Microsoft Excel worksheet was lost.
代码如下:
With Worksheets("Pivot").PivotTables(1).PivotCache
.Connection = Array( _
"OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=" & ThisWorkbook.FullName & ";Mode=Share" _
, _
" Deny Write;Extended Properties=""HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password=""" _
, _
""";Jet OLEDB:Engine Type=35;Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transacti" _
, _
"ons=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't" _
, _
" Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False" _
)
.CommandType = xlCmdTable
.CommandText = Array("SELECT * FROM [Data$]")
.MaintainConnection = True
.Refresh '总在这里出错
End With
请问是什么原因,应该怎么解决呢?谢谢! |
|