DoCmd.TransferSpreadsheet from Excel to Access using sheet codename - NOT tabname

shanesuzanne

New Member
Joined
Dec 1, 2016
Messages
21
Table name is employees
File name is varFile (used with a file picker)

This works:

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "employees", varFile, False, "January!A4:AD10000"


The problem is the tab names change each month. For the life of me, I can't get the sheet codename to work. This is sheet(1). I've googled for HOURS. Can anyone point me in the right direction?

The code is in Access 2010, importing from Excel 2013. Thanks!
 
Last edited:
I have had many situations like these before, and while it is common sense and good practice to force your originators (source of files) to adhere to naming conventions, this is not always possible and anything human is error-prone.
What I have done in the past is to use the Excel object to open the files in question and loop through the worksheets using a pattern within the sheet to *guess* what the sheet is and to ask the user to confirm. Then it is easy to use the actual names in the Access Import. In my experience, that is not only very reliable, but would add sufficiently more grief to the operator that it might even pressure the originators to adhere to naming conventions!
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,215,573
Messages
6,125,608
Members
449,238
Latest member
wcbyers

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