问题
Even after searching and trying for a long time I am not sure whether it is possible it or not.
I have a PP model using SQL source. Let's say command is:
select * from FactInternetSales where CustomerKey = 11001
and I have filter, 'CustomerKey' and based on the filter selection I want to update the command. For e.g:
select * from FactInternetSales where CustomerKey = 11002
The code I am trying is:
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"
Trying to assign a command results in 'Run-time error 1004'
I just come across this link, it seems possible. But I am not getting the 'temporary tables' part. Please share your opinion (and the VBA) code you have used to address this.
Thanks, Prakash
回答1:
I see my own question here after a long time. I have already found the solution so answering my own question.
The solution is that the connection need to be created from Excel Data menu and load/import the data from there ('Only Create Connection' and 'Add this data to Data Model'). The Data Model is marked read-only if the creation is created using PP window. And also if the tables/fields are renamed/added after importing from Excel Data menu, the Data Model is marked read-only but no problem in relationship and measures creation/addition.
Thanks
来源:https://stackoverflow.com/questions/31374729/using-vba-to-add-or-change-power-pivot-data-connection