importing text files using VisualBasic

khickey

New Member
Joined
Apr 16, 2002
Messages
16
G'day

This is probably a simple question, but using VB what code do I need to have a text file imported into a worksheet. I have about 200 files in one directory that I want to import one after the other. Is there a way to get VB to import one, complete the macro that I want to apply (it does some calculations then prints and saves the workbook) and then automatically open the next .txt file in the directory and do it all again until all the files have been processed ( and then stop)?

thanks in advance

Cheers
ken
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Yes that is easy to do, but in this case it will difficult for you to get a good code example unless you can provide some more details...
How familiar are you with VBA?

Tom
 
Upvote 0
Unfortunately, I have only just started using VBA and I need to get this macro up and working by tomorrow.

The files I have to process are all text files with different names, but all having the .txt extension.

I have created a Macro such that, once the files are imported, sorts the data, does some statistics, fills in a summary sheet, prints the result, saves it and closes the file. I am only using import to get the data in because it seemed the only way I could easily retain the worksheet name "Sheet1", which I have used in my subsequent Macro when wanting to refer back to the sheet with my data in it (when I tried to use "Open", the first sheet in the workbook that contained the data was automatically given the name of the imported file and because that is different for each file, I didn't know how to refer to that sheet in the macro). My macro is very clumsy, but it works, if I can get the files into worksheet easily to start with (that is why I would love it if the Macro would open them all sequentually, without me having to open each one individually)

Cheers
Ken
 
Upvote 0

Forum statistics

Threads
1,213,568
Messages
6,114,348
Members
448,570
Latest member
rik81h

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top