?
Solved

How do I loop through a folder, import only the data from A5:LastRow and kill each file?

Posted on 2015-01-07
9
Medium Priority
?
238 Views
Last Modified: 2015-01-07
I have a folder of formatted macro enabled spreadsheet forms with multiple tabs and data to import and append to an Access 2010 table.  The top 4 rows of the target tab are a header that can be excluded from the import, so what I want to do is grab everything on that one tab from A5 to the bottom, which is different in each file.

I want to loop through the folder, import and kill each file after the import.  Does anyone have a chunk of code for that?
0
Comment
Question by:Jay Williams
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40535581
this is a whole process of file archiving you are asking.

this may help you to start what you want to do

http://allenbrowne.com/ser-59.html
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40535611
here is the code to search for excel files in a single folder

dim sPath as string, xlFile as string
sPath="C:\myfolder\"

xlFile=dir(spath & "*.xls*")

while xlFile<>""
    debug.print xlfile
    docmd.transferspreadsheet acimport , , "tablename", spath & xlfile, false, "sheetname!A5:Z1000"

    'delete the file

    kill spath & xlfile
   xlFile=dir()
wend
0
 

Author Comment

by:Jay Williams
ID: 40535625
Thanks, Rey.  This is more appropriate--simple, like me.  Will the Z1000 take me to the last row with entries, or will it only take me to row 1000?
0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40535635
only to row 1000.., i just placed it there :-)
0
 

Author Comment

by:Jay Williams
ID: 40535658
OK. The data may go farther than that. Another way to go would be to import only rows where column D is populated.  Would that be hard to specify?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40535668
well, you need to open the excel file to determine the last row that have data.

i suggest that you just extend the 1000 to get all data.
0
 

Author Comment

by:Jay Williams
ID: 40535736
Well, F1 does not exist in the destination table. I changed the field names argument to "True", knowing it wouldn't work, and it didn't. The sheet and table structures are the same. How do I fix that?
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 40535757
import the excel file to a temp table, then create an append query to append the records from temp table to the  final table.
0
 

Author Closing Comment

by:Jay Williams
ID: 40535853
Thanks a lot, Rey. Works like a charm.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Make the most of your online learning experience.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question