Import all active wrksheets from multiple wrkbooks

jwh

New Member
Joined
Jun 21, 2005
Messages
3
I have a folder containing a variable number of workbooks. I want to copy all of the active worksheets from those workbooks into a summary workbook. Then I will use code from Ron D that will create a summary worksheet.

I have not been able to find something that actually gets all active worksheets and imports them to a workbook - please help

Jay
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Jay welcome to the forum,

Take a look at this code to see if it helps.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Open_My_Files()<br><SPAN style="color:#00007F">Dim</SPAN> MyFile <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> MastWB  <SPAN style="color:#00007F">As</SPAN> Workbook<br><SPAN style="color:#00007F">Dim</SPAN> SalesWB <SPAN style="color:#00007F">As</SPAN> Workbook<br><SPAN style="color:#00007F">Set</SPAN> MastWB = Workbooks("MasterWorkbook") <SPAN style="color:#007F00">'change to suit</SPAN><br>MyPath = "M:\Access Files\"<br>MyFile = Dir(MyPath)<br><br><SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">While</SPAN> MyFile <> ""<br><SPAN style="color:#00007F">If</SPAN> MyFile <SPAN style="color:#00007F">Like</SPAN> "*.xls" <SPAN style="color:#00007F">Then</SPAN><br>Workbooks.Open MyPath & MyFile<br><br>    <SPAN style="color:#00007F">Set</SPAN> SalesWB = ActiveWorkbook <SPAN style="color:#007F00">'change to suit</SPAN><br>    SalesWB.Sheets.Copy Before:=MastWB.Sheets(MastWB.Sheets.Count)<br>ActiveWorkbook.Close <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br>MyFile = Dir<br><SPAN style="color:#00007F">Loop</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
I tried this code and it gives me a subscript out of range for the masterworkbook or the mypath - although I copied them identical
 
Upvote 0
Do you have Option Explicit at the top of the module if so you have to declare myPath as String. Add this in near the top

Dim myPath as String
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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