473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Import mulitiple excel files to access table

Hello,

I am struggling to import multiple spreadsheets into an Access table. I have "borrowed" the code from the 'net and tailored it slightly. I am using Access 2013. Code is as follows:

Expand|Select|Wrap|Line Numbers
  1. Function Impo_allExcel()
  2. Dim ImportDir As String, ImportFile As String
  3. ImportDir = "\\-server\WarehouseKPIs\DB_Linked_Forms_Folder\"
  4. ImportFile = Dir(ImportDir & "*")
  5. Do While ImportFile <> ""
  6. DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel18, Tbl1_Warehouse_Form_Archive, ImportDir & ImportFile, , Form
  7. ImportFile = Dir
  8. Loop
  9. End Function
  10.  
Any help would be much appreciated.

Thanks.
Apr 22 '14 #1
7 8151
zmbd
5,501 Expert Mod 4TB
1) You're making us guess here:
1a) Do you have multiple excel workbooks where-in there is at least one worksheet that you would like to import the data
1b) You have a single excel workbook where-in there are multiple worksheets
1c) a combination of 1a and 1b

2) Not Sure what you are doing in line 6
2a) what is that "form" doing at the end of the statement
Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferSpreadsheet _
  2.     TransferType:=acImport, _
  3.     spreadsheettype:=acSpreadsheetTypeExcel8, _
  4.     tablename:=Tbl1_Warehouse_Form_Archive, _
  5.     fileName:=ImportDir & ImportFile
2b) are you sure that you are using such an old version of the worksheets? acSpreadsheetTypeExcel8= excel97

3) By, simply stating that your code "doesn't work," posting code that appears to have had very little if any troubleshooting performed, and expecting someone to help doesn't usually result in much of an answer and may result in your thread being deleted. Instead, please tell us what you were expecting to happen and what actually happened.

For each error, if any: the EXACT title, error number, and descriptions that occurred and at what line in your posted code the error occurred.

These are the minimum requirements for posting a question of this nature.
Apr 22 '14 #2
Hi thanks for your response.

To clarify:
1) I have multiple (50+) excel files in a folder (containing subfolders), that I would like to import in one hit to Access. The excel files all have the file extension .xls. I would like to import the "Form" range from these spreadsheets into the Tbl1_Warehouse_Form_Archive table.
2. Form refers to the Excel range, I have corrected the Excel file type to 18.
3. Issues - the code is falling down at the following points:
Expand|Select|Wrap|Line Numbers
  1. [ImportDir = "\\server\insert_full_path_here\"]
  2.  
  3. [ImportFile = Dir(ImportDir & "*")]
  4.  
  5. [Do While ImportFile <> ""]
I can see that the ImportFile part may not work due to referring to the ImportDir, which isn't working. The same is true for the "Do While ImportFile" line, which is dependent on the ImportFile segment of the code.

I am relatively new to VBA, and have had success with several bits of code. I have "stepped-into" this code, and couldn't see what was wrong, hence my post here. I will describe my issue in more depth should I post here again.

Thanks again.
Apr 23 '14 #3
jimatqsi
1,271 Expert 1GB
I can't say anything about version 2013, but in 2007 and earlier I don't believe you can add that "*" do the Dir() folder. Just
Expand|Select|Wrap|Line Numbers
  1. ImportFile=Dir(path)
  2. do while ImportFile <> ""
  3.    (do stuff - including test the file type to be sure it's what you want )
  4.     ImportFile=Dir()  ' to get the next file in the list
  5. Loop
  6.  
Jim
Apr 23 '14 #4
zmbd
5,501 Expert Mod 4TB
Hi thanks for your response.
1) I have multiple (50+) excel files in a folder (containing subfolders), that I would like to import in one hit to Access.
That's a very tall order.
You can use the DIR() method to handle the main directory path fairly easily; however, the subfolders will be much more complicated and your code, as is, will not handle that scenario; however, let's just try to handle the main directory files first.

I would like to import the "Form" range from these spreadsheets into the Tbl1_Warehouse_Form_Archive table.
2. Form refers to the Excel range,
Form is a reserved token/name
Access 2007 reserved words and symbols
AllenBrowne- Problem names and reserved words in Access

Second the range name needs to be in quotes i.e:"NameOfImportRange"

Third I advise that very new programmers use the named parameters when first creating their code as I've shown in my last post in section (Post#2 - Sec2A). This way you do not need to worry about the comma placement.

I have corrected the Excel file type to 18. (The excel files all have the file extension .xls.)
Type 18?
If you mean "acSpreadsheetTypeExcel18" that is, TBK, an invalid type.
We need to know what version of Excel was used to create the file. With "xls" either acSpreadsheetTypeExcel8 or acSpreadsheetTypeExcel9 are the most likely types to use.

3. Issues - the code is falling down at the following points:
Yea 20Q... For each error, if any: the EXACT title, error number, and descriptions that occurred and at what line in your posted code the error occurred.

Please follow the advice and basic troubleshooting here:[*]> Before Posting (VBA or SQL) Code you will need to repeat, fixing errors as found, the compile step until no errors occur.
Apr 23 '14 #5
Hi, I have solved this using alternative code, I tailored it to search all of the key sub-folders. The reference to the named range "Form" worked fine, but will avoid using reserved words in future.

Thanks.
Apr 25 '14 #6
zmbd
5,501 Expert Mod 4TB
most welcome.
Would you mind sharing your solution?
It can be quite helpfull to others with similuar issue, and sometimes we can help streamline the code or help to avoid a potential bottle-neck.
Apr 25 '14 #7
Expand|Select|Wrap|Line Numbers
  1. Public Function Impo_allExcel()
  2. Dim myfile
  3. Dim mypath
  4.  
  5. mypath = "\\server\insert_the_full_path_here\subfolder_1"
  6. ChDir (mypath)
  7. myfile = Dir(mypath)
  8. Do While myfile <> ""
  9.   If myfile Like "*.xls" Then
  10.     DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "Demo_Table", mypath & myfile, , "Form"
  11.   End If
  12.   myfile = Dir()
  13. Loop
  14.  
  15. mypath = "\\server\insert_full_path_here\Weekend Shift\"
  16. ChDir (mypath)
  17. myfile = Dir(mypath)
  18. Do While myfile <> ""
  19.   If myfile Like "*.xls" Then
  20.     DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "Demo_Table", mypath & myfile, , "Form"
  21.   End If
  22.   myfile = Dir()
  23. Loop
  24.  
  25. End Function

So I have trimmed this code down to access two folders, I have twelve folders total. It searches/imports the contents of one folder, loops until completed and moves onto the second folder. The code then ends. These folders contain submitted Excel forms for the current month - when the month is complete, I then archive these into a dedicated Month subfolder. Then the folder referred to in the code is repopulated automatically with the newly submitted sheets for the new month. The "Form" part of the DoCmd.TransferSpreadsheet acImport statement is the named range in my excel sheets, if anyone else comes to use this code.

Thanks.
Apr 25 '14 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: mednyk | last post by:
It's very simple import, without any data modifications; from several excel files to one table. I tried the wisard and it gives me selection for only one file. I am not used to create DTS...
3
by: Santa-D | last post by:
I've got an excel sheet that I need to import into a table, however, I want the function to automatically manipulate the data prior to it being imported. For example, i have a field called and...
6
by: pietlinden | last post by:
I have a large number of Excel files that contain Survey questions and responses (I know the design is awful... I inherited this mess). Basic structure is like this: Demographic Questions | ...
1
by: rrstudio2 | last post by:
I was reading and modifying some VB code needed to import all of the excel files in a directory into one table in Access and ended up with the following which works. Public Sub...
11
by: MD | last post by:
Hello, I need to import a sheet of 884 different excel-file with same lay- out. The sheet name is 'Totaal' and is the same in all different files. Is there a script (module) in order to: 1....
5
by: hushens10 | last post by:
Access Naive - Help Needed I am using Access 2003 and Excel 2003. My goal is to create a database for a school where each student's testing information can be stored and organized so that it can...
7
by: ivancycheng | last post by:
I have around 400 excel files with same format (multiple sheets) and wants to import few sheets from excel to MS Access (XP version) for further processing. any one can advise me how to do it? (I'm...
12
by: anand padia | last post by:
I have a master access table where we store all the employee information. I have various application developed in excel which imports and uses information in master. Now I want to develop a excel...
13
by: WU JU | last post by:
Hi. I have thousands of excel files in one directory. I want to build up the Access table from excel files. Each excel file has one worksheet, but I don't need every column and low of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.