Can we browse and copy all the sheets

GirishDhruva

Active Member
Joined
Mar 26, 2019
Messages
308
Hi Everyone ,

Can we browse and copy all the sheets to Master sheet.

Like if i browse for a "Abc" excel workbook, it should copy all the sheets that are available in "Abc" workbook and paste that in Master workbook

Can this be done any suggestion?????

Here is what i tried
Code:
Sub Browse_And_Add_Sheets()
Dim ws As Worksheet
Range("A2").Select
myfile = Application.GetOpenFilename(, , "Browse for Workbooks")


Workbooks.Open myfile
For Each ws In ActiveWorkbook.Worksheets
    If ws.Name Like "Live Employees" Then
        Sheets("Live Employees").Copy After:=Workbooks("Master").Sheets(1)
        Sheets("Master").Select
    ElseIf ws.Name Like "EsiReport" Then
        Sheets("EsiReport").Copy After:=Workbooks("Master").Sheets(1)
        Sheets("Master").Select
Next ws


Windows("Master.xlsm").Activate
End Sub

But from the above code it searched for that sheet name , instead of that i need to copy all the sheets that are available

Thanks in advance
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi Everyone ,

Can we browse and copy all the sheets to Master sheet.

Like if i browse for a "Abc" excel workbook, it should copy all the sheets that are available in "Abc" workbook and paste that in Master workbook

Can this be done any suggestion?????

Here is what i tried
Code:
Sub Browse_And_Add_Sheets()
Dim ws As Worksheet
Range("A2").Select
myfile = Application.GetOpenFilename(, , "Browse for Workbooks")


Workbooks.Open myfile
For Each ws In ActiveWorkbook.Worksheets
    If ws.Name Like "Live Employees" Then
        Sheets("Live Employees").Copy After:=Workbooks("Master").Sheets(1)
        Sheets("Master").Select
    ElseIf ws.Name Like "EsiReport" Then
        Sheets("EsiReport").Copy After:=Workbooks("Master").Sheets(1)
        Sheets("Master").Select
Next ws


Windows("Master.xlsm").Activate
End Sub

But from the above code it searched for that sheet name , instead of that i need to copy all the sheets that are available

Thanks in advance

Can this be done , any Ideas are appreciated
 
Upvote 0
How about
Code:
Sub GirishDhruva()
   Dim Ws As Worksheet
   Dim Wbk As Workbook
   Dim Fname As String
   
   Fname = Application.GetOpenFilename(, , "Browse for Workbooks")
   Set Wbk = Workbooks.Open(Fname)
   
   For Each Ws In Wbk.Worksheets
      Ws.Copy , ThisWorkbook.Sheets(1)
   Next Ws
   Wbk.Close False
End Sub
 
Upvote 0
How about
Code:
Sub GirishDhruva()
   Dim Ws As Worksheet
   Dim Wbk As Workbook
   Dim Fname As String
   
   Fname = Application.GetOpenFilename(, , "Browse for Workbooks")
   Set Wbk = Workbooks.Open(Fname)
   
   For Each Ws In Wbk.Worksheets
      Ws.Copy , ThisWorkbook.Sheets(1)
   Next Ws
   Wbk.Close False
End Sub
Thanks @Fluff it worked perfectly
 
Upvote 0
You're welcome & thanks for the feedback.

Also please do not quote entire posts, as it just clutters up the thread.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,392
Messages
6,119,254
Members
448,879
Latest member
oksanana

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