open multiple files question

Herman

New Member
Joined
Feb 28, 2002
Messages
28
I want to open multiple files from a specific directoy in excel, with the following code every file is opened as a seperate workbook.
My question is is it possible to do this from within a workbook so that every file found isn't opened as a workbook but as a new sheet in the workbook where i ran this code

Sub Macro1()

Set fs = Application.FileSearch
With fs
.LookIn = "C:Mijn documenten"
.FileName = "*.txt"
If .Execute > 0 Then
MsgBox "Er zijn " & .FoundFiles.Count & _
" files found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Workbooks.Open FileName:=.FoundFiles(i)
Next i
Else
MsgBox "no files found."
End If
End With

End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
What you will have to do within the loop
is to;
After opening the file Copy over all the
sheets then close the file.
Then do the same with the next Workbook
opened.

Turn your macro recorder on and see what you get...incorporate the code into your code.
Post back if any problems.
 
Upvote 0

Forum statistics

Threads
1,213,526
Messages
6,114,122
Members
448,550
Latest member
CAT RG

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