Import all 'bas' files to a new excel spreadsheet

Excel2006

Active Member
Joined
Dec 19, 2006
Messages
455
Hi

Following on from this thread, is there a way you can

Import all 'bas' files in a network folder to a new excel spreadsheet.

If you have say 30 modules in one spreadsheet and you want to export them all to another spreadsheet,

I have the code below, and I get an error in the line:

fn.FoundFiles.Import _
Filename:="L:" & "" & "book2" & ".xls"


Sub ImportAllVBA()

'Need to change code


Dim fs As FileSearch, ws As Worksheet, i, j As Long
Dim f, mySubFolders, aFolder
'Dim VBComp As VBIDE.VBComponent
Set fs = Application.FileSearch

With fs
.SearchSubFolders = False ' set to true if you want sub-folders included
' .FileType = msoFileTypeAllFiles 'This lists all files


fn = InputBox("Which directory do you want files from?", , "L:\VBAcode")
.LookIn = fn
'.LookIn = "L:" 'modify this to where you want to search
If .Execute > 0 Then

'Set ws = Worksheets.Add
Workbooks("book2.xls").Activate

For i = 1 To .FoundFiles.Count

fn.FoundFiles.Import _
Filename:="L:" & "\" & "book2" & ".xls"

Next

End If

End With

End Sub
 

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.

Forum statistics

Threads
1,181,730
Messages
5,931,703
Members
436,799
Latest member
BasOo

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
Top