473,385 Members | 1,838 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,385 software developers and data experts.

Scanning directory of excel files

3
Hi all, I have a vb question that i'm hoping I can get some help with.

I have a directory of excel files (probably about 1000) of them. They are quote sheets for the company I work for, and they are all the exact same format. I need to create some code in vb using microsoft access that will scan through this directory of excel files, and pull certain cells of information from each of them, and store this information into an access database.

Right now I can scan a single excel file into a database, but it scans the ENTIRE file, and like I said it's only a single file, I need to be able to scan a whole directory of them using a loop.

Anybody have any code that will help me out with this? Thanks a lot, appreciate any help.
Mar 19 '08 #1
7 2078
Sick0Fant
121 100+
Hi all, I have a vb question that i'm hoping I can get some help with.

I have a directory of excel files (probably about 1000) of them. They are quote sheets for the company I work for, and they are all the exact same format. I need to create some code in vb using microsoft access that will scan through this directory of excel files, and pull certain cells of information from each of them, and store this information into an access database.

Right now I can scan a single excel file into a database, but it scans the ENTIRE file, and like I said it's only a single file, I need to be able to scan a whole directory of them using a loop.

Anybody have any code that will help me out with this? Thanks a lot, appreciate any help.
I can tell you that it is possible to reference single cells. Workbooks have Worksheets and worksheets have cells.

As for opening all of the files... VB gives you a function to retrieve all the files from a directory.
Mar 19 '08 #2
Killer42
8,435 Expert 8TB
When you say you can "scan" a single file into a database, I guess you must be referring to the import function.

I think what you will need to do in this case is use something like the FileSystemObject to scan through all the "*.XLS" files in the directory, open each one in your VB application, extract the cell in question, and INSERT the value into your database.

We can help out, but I'd recommend you try to put together as much of it as possible for yourself, as you'll understand it a lot better that way.

By the way, what versions of VB, Excel and Access do you have? Also, are you using standalone VB, or the (very similar) VBA macro language built into Access or Excel?
Mar 20 '08 #3
Killer42
8,435 Expert 8TB
Oh, one other thing. If you try the search box, you'll find there have been plenty of discussions here on working with both Excel worksheets and Access tables in VB. Though they're not usually used in combination, this shouldn't be any particular barrier.
Mar 20 '08 #4
paul86
3
Sorry, been really busy and haven't checked this thread in a little while, thanks for your responses though. I'm using the VB built into Access. I'm not using any sort of import function as of right now...this is the code i'm using right now to import an excel file into the access database.

Expand|Select|Wrap|Line Numbers
  1. Sub test()
  2. Dim con As New ADODB.Connection
  3.  
  4. con.Open _
  5.    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\sampleimport2.mdb;Jet OLEDB:Engine Type=4"
  6.  
  7. Dim strSQL As String
  8. strSQL = "SELECT * INTO Table5 FROM [Sheet1$] IN ""C:\test.xls"" ""Excel 8.0; HDR=No;"""
  9.  
  10. con.Execute strSQL
  11.  
  12. con.Close
  13. Set con = Nothing
  14. End Sub
  15.  
Like I said, this code works fine, but there are a couple problems.

1) It only imports the ONE file, I need to be able to scan through a directory and import info from lots of them.

2) It's importing the entire excel file. I need to be able to just pick certain cells of text to import, not the entire file. I've been fiddling around with it but just can't seem to get anything to work.

If you have any suggestions it would be greatly appreciated. Thanks guys.
Mar 26 '08 #5
paul86
3
Any tips? Thanks guys. :)
Mar 31 '08 #6
QVeen72
1,445 Expert 1GB
Hi,

Open one more Connection Object for Excel:

Expand|Select|Wrap|Line Numbers
  1. Dim ExConn As New ADODB.Connection
  2. With ExConn
  3.     .Provider = "Microsoft.Jet.OLEDB.4.0"
  4.     .Properties("Extended Properties").Value = "Excel 8.0"
  5.     .Open "C:\Book1.xls"
  6. End With
  7. Dim RST As New ADODB.RecordSet
  8. RST.Open "Select * From [Sheet1$] Where ColName='MY_Condition'",ExConn
  9. 'Or
  10. 'Sheet With Range:
  11. RST.Open "Select * from [Sheet1$A1:B20]", ExConn 
  12.  
Regards
Veena
Mar 31 '08 #7
Killer42
8,435 Expert 8TB
Interesting...

That looks like the sort of information that should go in a HowTo, Veena. It's the kind of thing that I never even guessed there was anything to know about.
Mar 31 '08 #8

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

Similar topics

2
by: Dean | last post by:
Hi I've got a question relating to using Javascript on an Intranet. I have a directory with a list of files in the format week36.xls, week37.xls and I want to write a script that will scan...
3
by: Hamed | last post by:
Dear Folks I am programming a page that asks user a directory name and lists files of type *.xls in the directory in client's machine. He/She will then select some files to upload them to the...
4
by: Zen | last post by:
I'm using Access 2000, and I'd like to know if there is a way to use a scanner (flatbed, doc-feed, etc) to scan forms with OMR or OCR software, and have the data be automatically (or if not...
4
by: Nazgob | last post by:
Hello! I'm looking for cross-platform directory scanning library working with ansi C. I need to use in in GNU Linux and Windows. I need to do simple directory and files opertionson both OS, can...
10
by: Alan Searle | last post by:
I would like to scan a directory structure into XML to offer navigation functionality in HTML / XSL pages. My questions are: 1. Which is the best structure to store variable depth heirarchies...
6
by: Bob Alston | last post by:
I am looking for others who have built systems to scan documents, index them and then make them accessible from an Access database. My environment is a nonprofit with about 20-25 case workers who...
4
by: tshad | last post by:
We have a few pages that accept uploads and want to scan the files before accepting them. Does Asp.net have a way of doing a virus scan? We are using Trendmicro to scan files and email but don't...
1
by: ahammad | last post by:
Hello, I would like to scan a certain directory for XML files. Then I want to take in every XML file, read it, and stores the contents as a string in an array. For example, if the directory has...
23
by: Rotsey | last post by:
Hi, I am writing an app that scans hard drives and logs info about every fine on the drive. The first iteration of my code used a class and a generic list to store the data and rhis took...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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,...

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.