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