1

I have an Oracle DB connection that pulls data from the DB into Excel. My only issue is that I want it pulled into a table rather than just dump the data into a sheet. My PivotTable needs to be refreshed based on the Table updating. This is my sample code that works. Is there a property for the QueryTables object that embeds the data into a table?

With ActiveSheet.QueryTables.Add(Connection:=Array(connection),Destination:=Range("A1"))

 .Sql = "SELECT * FROM TABLE"
 .FieldNames = True
 .Refresh BackgroundQuery:=False
End With

1 Answer 1

1

Consider using a ListObject with the Query Table. Below is an example with a MySQL connection.

Dim constr As String

constr = "ODBC;DRIVER={MySQL ODBC 5.3 Unicode Driver};server=localhost;_
          database=databasename;UID=username;PWD=password;"

With ActiveSheet.ListObjects.Add(SourceType:=0, _
          Source:=constr, _
          Destination:=Range("$A$1")).QueryTable

    .CommandText = "SELECT * FROM `Table`"
    .ListObject.DisplayName = "TableName"  
    .Refresh BackgroundQuery:=False
End With
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.