Copy list of workbooks ( one sheet only) to one workbook in tab number order

David123456

New Member
Joined
Jul 16, 2014
Messages
48
Can anyone assist with a formula.

Take a list of workbooks ( only1 worksheet in each workbook) say the workbooks are held in the y:\ and called 1980-001,1980-002 up to 1980-250

I want to copy all these individual workbooks to one workbook in tabs in file number order.

So the first tab would be 1980-001 the next tab would be 1980-002 and so on depending o how many workbooks there are.

My formula doe this but does not add the workbook name to the tab and also does not copy them over in number order.


Any help greatly appreciated
 
Sub GetSheets()
Path = "Y:"
Filename = Dir(Path & "*.xls")
Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
ActiveWorkbook.Worksheets(1).Copy After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)
ActiveSheet.Name = Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1)
Workbooks(Filename).Close
Filename = Dir()
Loop
End Sub


Does not work Comes back with run time error.
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
ActiveSheet.Name = Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1)

Andrew,

This formula it comes back with a run time error.
 
Upvote 0
When you get the error go to the Immediate window (press Ctrl+G if you can't see it), type:

?ActiveWorkbook.Name

and press Enter. What does it return (in the row below).
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,050
Members
449,206
Latest member
Healthydogs

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