473,624 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Scanning directory of excel files

3 New Member
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 2092
Sick0Fant
121 New Member
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 Recognized Expert Expert
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 FileSystemObjec t 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 Recognized Expert Expert
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 New Member
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 New Member
Any tips? Thanks guys. :)
Mar 31 '08 #6
QVeen72
1,445 Recognized Expert Top Contributor
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 Recognized Expert Expert
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
17631
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 all the files in the directory and select the one with the highest week number then display in the browser window. A brief search hasn't revealed any code to do this so I just want to know if it is possible and what the function names are that...
3
14073
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 server. Is there any way to ask a directory name and then list the files of that directory in client's machine? The typical browser that is used is IE but I am not allowed to use ActiveX objects.
4
3227
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 automatically then using a macro or other means) entered into tables. I guess the real question is do I need to use an expensive program to do this or is it codable suing Access/VB, and if it is codable, any suggestions as to how to start? Many...
4
2071
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 you recomend me some solution? Thank you in advance. Regards, Nazgob
10
2070
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 in XML (i.e. different branches of the directory structure will have different 'depths'). 2. I am currently using VBA to prepare the pages and export to XML and
6
3856
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 use laptops. They have Access databases on their laptops and the data is replicated. The idea is that each case worker would scan their own documents, either remotely or back at the office. And NO I am not planning to store the scanned...
4
1368
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 know if we can use it with our pages to handle files that our clients upload. Is there some type of API that would allow us to do this? I want to be able to Upload Word files using: <input id="MyFile" visible="true" style="width:200px"...
1
1631
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 file1.xml, file2.xml, and file3.xml, they would all be scanned and read. Then, all the contents of file1.xml would be stored in an array as the first element: @array would contain the stuff in file1.xml @array would contain the stuff in file2.xml...
23
3731
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 13min on my 60 GB drive. I wanted it to be quicker.
0
8233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8170
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8675
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8334
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6108
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2604
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.