R
Rob
I have some code which should import data from an Excel Worksheet, but
it's not quite working.
The user is prompted to enter a workbook, a worksheet name and then
(via some other code) the columns for two fields to import. So before
this part of code is processed, we have workBookName, workSheetName,
importColumn1, and importColumn2.
I want to import the data on the worksheet "workSheetName" in column
numbers "importColumn1" and "importColumn2" to a new table in Access.
The top row of the data contains my field names.
How can I use the TransferSpreadsheet method to do this? I try
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8,
"NewTable", workBookName, TRUE, ---MyRange---
.... but whatever in use for "MyRange" seems to fail.
For example, let's say I want to import columns 4 and 8. I can use
Excel's range.address property to get that Range1, the region of
interest in column 4, is D1
4000, and Range2, the region of interest
in column 8 is H1:H4000. I thus try
MyRange = workSheetName & "!" & Range1 & "," & workSheetName & "!" &
Range2.
This translates to MyRange = "Sheet2!D1
4000,Sheet2!H1:H4000",
but I get the error "Cannot find object
"Sheet2$$D1
4000,Sheet2$$H1:H4000" (Note the funny thing it's doing to
the exclamation point).
I've tried other versions of MyRange, but it's just not working. Maybe
it's because the range is not a single region?
it's not quite working.
The user is prompted to enter a workbook, a worksheet name and then
(via some other code) the columns for two fields to import. So before
this part of code is processed, we have workBookName, workSheetName,
importColumn1, and importColumn2.
I want to import the data on the worksheet "workSheetName" in column
numbers "importColumn1" and "importColumn2" to a new table in Access.
The top row of the data contains my field names.
How can I use the TransferSpreadsheet method to do this? I try
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8,
"NewTable", workBookName, TRUE, ---MyRange---
.... but whatever in use for "MyRange" seems to fail.
For example, let's say I want to import columns 4 and 8. I can use
Excel's range.address property to get that Range1, the region of
interest in column 4, is D1

in column 8 is H1:H4000. I thus try
MyRange = workSheetName & "!" & Range1 & "," & workSheetName & "!" &
Range2.
This translates to MyRange = "Sheet2!D1

but I get the error "Cannot find object
"Sheet2$$D1

the exclamation point).
I've tried other versions of MyRange, but it's just not working. Maybe
it's because the range is not a single region?