Click here to Skip to main content
15,911,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day all,

I have imported data into my excel datamodel and have been able to import that back into a sheet using :

VB
Application.CutCopyMode = False
    Application.DisplayAlerts = False
    
    Dim tbl As ListObject
    Dim ws As Worksheet
    
    Set ws = ThisWorkbook.Worksheets.Add
    
    connectionName = fieldName & "sConnection"
    
    With ws.ListObjects.Add(SourceType:=4, Source:=ActiveWorkbook.Connections("Query - 
        TRENDS_GroupData"), Destination:=Range("$A$1")).TableObject
        .WorkbookConnection.OLEDBConnection.CommandText = Array( _
            "Evaluate" & Chr(13) & "" & Chr(10) & "Calculatetable" & Chr(13) & "" & 
             Chr(10) & "(DISTINCT(UNION(" & Chr(13) & "" & Chr(10) & 
             "Distinct(Trends_MyCoData[" & fieldName & "])," & Chr(13) & "" & Chr(10) 
             & "Distinct(Trends_GroupData[" & fieldName & "])" & Chr(13) & "" & 
             Chr(10) & ")))")
        .WorkbookConnection.OLEDBConnection.CommandType = xlCmdDAX
        .RowNumbers = False
        .PreserveFormatting = True
        .RefreshStyle = 1
        .AdjustColumnWidth = True
        .ListObject.DisplayName = fieldName
    End With
    
    Set tbl = ActiveSheet.ListObjects(1)
    tbl.Refresh
In another workbook I use an ADODB.Connection to query a table on a worksheet with a table using :
VB
Public Function CreateSQLConnection() As Object
   
    '---Connecting to the Data Source---
    Set CreateSQLConnection = CreateObject("ADODB.Connection")
    With CreateSQLConnection
        .Provider = "Microsoft.Mashup.OleDb.1"
        .ConnectionString = "Data Source=ActiveWorkbook.Connections(""Query - 
         TRENDS_GroupData"");" & _
        "Extended Properties=""Excel 12.0 Xml;HDR=NO"";"
        .Open
    End With

End Function
These to options have been working great however I have now come accross a much larger dataset and was wondering if it is possible to use the Connection as a source for the ADODB.Connection as I have so far met with no success.

The closest I have come to getting it to work pops up the following message :
"Cannot update. Database or object is read-only."

All in all my end goal is to be able to query the data model using SQL, if there is another way to do it instead of the above I would appreciate the guidance.

Any thoughts would be highly appreciated.

What I have tried:

Changing the mode to Read or adRead
Changing the provider to JET or Mashup
A few permutations of different settings.
Posted
Updated 30-May-18 1:05am
v3
Comments
CHill60 29-May-18 10:13am    
When you say "a much larger dataset" have you exceeded the limits on Excel object sizes?
Scs11Dr1v3 29-May-18 23:41pm    
Good morning CHILL60,

The dataset is well over 1 000 000 lines of data which exceeds Excel's worksheet constraints, however It is still well within the bounds of Excels datamodel capacity.
CHill60 30-May-18 6:53am    
Max size is dependant on version and platform, neither of which is mentioned, but if you're sure...
If it was me I'd be experimenting to find the threshold that breaks the model or seeing if there was an alternative approach to getting the MI.
Scs11Dr1v3 30-May-18 7:02am    
My apologies I did not think to mention it.

I am working in Excel Professional Plus 2016 Version 1804 Build 9226.2156

Nothing is breaking or not running, Both methods above work great, I would simply like to combine them.

My end goal is to be able to query the data model with SQL statements instead of querying worksheets.

Thank you for the feedback
CHill60 30-May-18 8:08am    
That's me getting the wrong end of the stick - sorry. That's why this conversation is in comments and not a solution :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900