2
即使搜索並嘗試了很長時間,我也不確定它是否可行。使用VBA添加或更改Power Pivot數據連接
我有一個使用SQL源的PP模型。比方說命令是:
select * from FactInternetSales where CustomerKey = 11001
和我有過濾器'CustomerKey'和基於篩選器選擇我想更新命令。對於如:
select * from FactInternetSales where CustomerKey = 11002
我想要的代碼是:
Dim mdl As ModelTable
Dim wcon As WorkbookConnection
Dim cmd As String
Set mdl = ActiveWorkbook.Model.ModelTables("Customers")
Debug.Print mdl.SourceWorkbookConnection.OLEDBConnection.CommandText
mdl.SourceWorkbookConnection.OLEDBConnection.CommandText = "select * from FactInternetSales where CustomerKey = 11002"
嘗試指派在「運行時錯誤1004」命令結果
我只碰到過這樣的link,它似乎可能。但我沒有得到'臨時表'的一部分。請分享您用於解決此問題的意見(和VBA)代碼。
感謝, 普拉卡什
1004意味着它是對象的只讀(或至少不允許編輯)財產,因此無法通過VBA分配,我還追着章在你的鏈接,腳本! – baldmosher
似乎連接不是隻讀的(如果您通過Excel嚮導創建而不直接在PP中),但CommandText是隻讀的[link](https://wordpress.training-nyc.com/vba/macro-to -change-powerpivot-data-connection /) – baldmosher
....但只要您在PP中編輯連接,它將使其完全只讀。 – baldmosher