Importing Multiple txt files using a macro: how?

Puma

Board Regular
Joined
Mar 19, 2002
Messages
72
I'm trying to write a generic open command in vba which opens all files with a particular file extension in a particular folder.

the best i can come up with so far is:

workbooks.opentext filename:= "C:Test" & "*" & ".txt" [etc.]

the only bit which doesn't work is the "*" bit. The macro runs but, only opens the "first" file in the folder, not all of them.

Anyone got any ideas?

Cheers,

Dave
This message was edited by Puma on 2002-04-22 03:51
This message was edited by Puma on 2002-04-22 03:51
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi Dave,

Sub OpenTextFiles()
Dim Fs, i
Set Fs = Application.FileSearch

With Fs
.LookIn = "C:Test"
.Filename = "*.txt"
If .Execute Then
For i = 1 To .FoundFiles.Count
Workbooks.OpenText Filename:=.FoundFiles(i)
Next
End If
End With
End Sub

Cheers back at yu!

Tom
 
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,051
Members
448,940
Latest member
mdusw

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