ODBC;DSN data connections. Can it pull range instead of a table?

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875

Hi, i'm using this connection to retrive data from workbook. but i want to retrive range and not table if possible.
Database1#accdb is my table name in workbook "find.". i'm running this code from Workbook "book1.xlsm"


Please advice.
Thanks in advance
Code:
[/FONT]
[FONT=Courier New]With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
        "ODBC;DSN=Excel Files;DBQ=E:\Personal_Files\Workbooks\Find.xlsm;DefaultDir=E:\Personal_Files\Workbooks;DriverId=1046;MaxBufferSize=20" _
        ), Array("48;PageTimeout=5;")), Destination:=Range("$A$1")).QueryTable
        .CommandText = Array( _
        "SELECT `Database1#accdb`.ID, `Database1#accdb`.Category, `Database1#accdb`.Budget, `Database1#accdb`.Actual, `Database1#accdb`.Department, `Database1#accdb`.Item, `Database1#accdb`.Month" & Chr(13) & "" & Chr(10) & "FROM `Databa" _
        , "se1#accdb` `Database1#accdb`")
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .ListObject.DisplayName = "Table_Query_from_Excel_Files"
        .Refresh BackgroundQuery:=False
    End With
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top