Import different excel files into MS Access 2010 tables automatically

我的梦境 提交于 2019-12-03 04:01:37

I think all you need to do is change the destination table name (the value of strTable) each time before you do DoCmd.TransferSpreadsheet.

In a comment you said you want the table name to be derived from the workbook file name. And, each time through your loop, another variable (strFile) contains the file name. So I think you could strip the file extension from that file name and use it as the Access table name.

Here is an Immediate window example which demonstrate how that can be done ...

strFile = "foo.xls"
strTable = Left(strFile, Len(strFile) - 4)
? strTable
foo

If that approach is suitable, revise the loop in your VBA code like this (untested) code snippet ...

strFile = Dir(strPath & "*.xls")
Do While Len(strFile) > 0
    strPathFile = strPath & strFile
    strTable = Left(strFile, Len(strFile) - 4)
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
        strTable, strPathFile, blnHasFieldNames
    strFile = Dir()
Loop

I used to be a MOS Access 2003. Now everyone is using 2010 but many things have not changed.

When you do a manual import or export, you can save the layout as a specification.

This process can be automated by a macro.

Check out the link below for more details and steps.

http://office.microsoft.com/en-us/access-help/run-a-saved-import-or-export-operation-HA001226020.aspx?CTT=5&origin=HA001226307

As for the other stuff, buttons, modules, etc, please read the on line help / documentation first.

We are here to help but not do the work for you.

J

Okay, I do not know if it is an issue with my computer not being on the current office CU.

http://msdn.microsoft.com/en-us/library/office/ff192475(v=office.14).aspx

Here is a link to how to use the ImportExport Macro. Use to be in the macro section.

I did read that you had to trust the location. So I tried both my location c:\msdn plus the default for the wizards.

Still was not able have it the option come up.

I tried creating a specification to see if one was needed for the option to show, no dice.

However, there is a DoCmd.TransferText and DoCmd.TransferSpreadSheet.

Both will allow you to import.

Create a function. Call the function from a macro (RunCode). Another way is to create a main menu form. Have a button. On the click command, run the code.

Please tell me if you ever get the ImportExportData Macro to show. I think it is a bug. I will need to bring down the latest Cumulative Updates and try again.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!