Import a Variable XLSM Range into Access with TransferSpreadsheet
Question details
Import a changing cell range from an XLSM workbook into an Access table using VBA.

- Product
- Microsoft Access 2010
- Device & OS
- not provided
- Scenario
- A VBA procedure formats an Excel workbook and imports a range whose row numbers vary.
- Observed behavior
- The import requires a compatible spreadsheet type and a text range; error 3011 may occur if Access cannot find the specified object.
Identify the XLSM file path, worksheet name, destination table, and first and last rows to import. Save any workbook changes before testing the transfer.
Pass the XLSM range as text to TransferSpreadsheet
Use the Excel 12 XML spreadsheet type and build the changing range from row-number variables.
In Access, press Alt+F11 and open the module containing the TransferSpreadsheet call.
Use an expression such as "A" & FirstTINonEmp & ":G" & NextEmp rather than passing an Excel Range object. Confirm that NextEmp is the last row you want to include.
Use this call, replacing the table name and variables as needed: DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12XML, "tblResultImport", defaultPath, False, "A" & FirstTINonEmp & ":G" & NextEmp
Run the procedure from the VBA editor, then open tblResultImport in Access to check the imported rows.
Check the worksheet and workbook when error 3011 occurs
Use these checks if Access cannot find the worksheet or range specified for the import.
Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for Microsoft Office formats, making it easy to move everyday spreadsheet work to WPS. It does not fix Microsoft Access TransferSpreadsheet errors.

Frequently Asked Questions
Which spreadsheet type should I use for an XLSM import in Access 2010?
Use acSpreadsheetTypeExcel12XML as the spreadsheet type in the DoCmd.TransferSpreadsheet call.
Can I pass an Excel Range object to TransferSpreadsheet?
No. Pass a text expression such as "A" & FirstTINonEmp & ":G" & NextEmp as the Range argument.
How do I import from a specific worksheet?
Include the worksheet name and a dollar sign in the range string, for example "Sheet1$A1:G10". Replace Sheet1 and the cell addresses with the values in your workbook.
Does error 3011 mean I need to copy the data to a new workbook?
Not necessarily. Check the file path, worksheet name, and range first. Save and close the workbook, then rerun the import to test whether its open state is involved.




