|
Question : Using Range in DoCmd.TransferSpreadsheet acImport
|
|
I tried to use "A:P,T:U,W:X" as my range in DoCmd.TransferSpreadsheet acImport but I got the error:
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "ntblNewItems", GetInputDirectory("New Business") & lstFileList, True, "A:P,T:U,W:X"
Runtime error 3011 The Microsoft Jet Database engine could not find the object 'A:P,T:U,W:X'
Is there a way to just import certain columns from a spreadsheet?
|
|
Answer : Using Range in DoCmd.TransferSpreadsheet acImport
|
|
Hello bejhan,
When importing from Excel, either through the UI or via TransferSpreadsheet, the Excel range must be contiguous, and any named range must be static (that is, the range refers to a fixed range, and is not defined by a formula).
The range you are trying to import is not contiguous. Try importing from A:X into a staging table, and then use an append query to move only the columns you want into your final destination table.
Nerdwood said: >>Umm... named ranges tend to be fairly dynamic, e.g. when you insert new rows, the range will >>expand automatically.
Umm... that depends. A static named range *will* expand if you explicitly insert a row or column in the range the Name refers to, and if you set up a "dynamic" Name (where the Name refers to a formula that fetches a range), that will also expand or contract according to the conditions in the formula. That said, if I make a QueryTable, set a Name to refer to the results range, and then refresh the QueryTable, it is not necessarily guaranteed that the Name will automatically adjust itself.
Regards,
Patrick
|
|
|
|