Macro to compile 6 active sheets into one workbook on 6 tabs

Ejohnson

New Member
Joined
May 20, 2003
Messages
14
I took a macro to open multiple files and adapted it to open text files into multiple workbooks. However, now that I have the open files, I can't figure out the macro to compile the active one sheet workbooks into a single workbook without limiting the macro to specific workbook names. Here is the portion I am having problems with.

Workbooks.Add
Windows("030325s.wri").Activate
Sheets("030325s").Select
Sheets("030325s").Move Before:=Workbooks("Book8").Sheets(1)
Windows("030325gw.wri").Activate
Sheets("030325gw").Select
Sheets("030325gw").Move Before:=Workbooks("Book8").Sheets(2)
Windows("030325as.wri").Activate
Sheets("030325as").Select
Sheets("030325as").Move Before:=Workbooks("Book8").Sheets(3)
Windows("030325ie.wri").Activate
Sheets("030325ie").Select
Sheets("030325ie").Move Before:=Workbooks("Book8").Sheets(4)
Windows("030325zp.wri").Activate
Sheets("030325zp").Select
Sheets("030325zp").Move Before:=Workbooks("Book8").Sheets(5)
End Sub

It opens a new workbook then moves the sheets to the new workbook. Is there a way to do this and use the active workbooks which are already open?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Re: Macro to compile 6 active sheets into one workbook on 6

The code below assumes it is located in a workbook that contains just code (i.e., no data).
Code:
Option Explicit

Sub testIt()
    Dim newWB As Workbook, aWB As Workbook
    Set newWB = Workbooks.Add
    For Each aWB In Application.Workbooks
        If aWB Is newWB Or aWB Is ThisWorkbook Then
        Else
            aWB.Sheets(1).Move before:=newWB.Sheets(1)
            End If
        Next aWB
    End Sub
 
Upvote 0

Forum statistics

Threads
1,221,700
Messages
6,161,378
Members
451,700
Latest member
Eccymarge

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