Importing Multiple Workbooks that have multiple worksheets

SloanRanger

New Member
Joined
Jul 12, 2020
Messages
8
Office Version
  1. 2010
Platform
  1. Windows
I’m trying to import a specific worksheet that appears in multiple (40) workbooks. I’m not fussed on how the worksheets are ordered in the new work book. The following code works but tried to pull all the worksheets and falls over when it finds hidden worksheets. As said I only want one worksheets copying.


Sub CombineWorkbooks()

Dim FName As String, FPath As String
Dim Sheet As Worksheet

Application.ScreenUpdating = False

FPath = Worksheets("Combine Sheets").Cells(2, 2).Value
FName = Dir(FPath & "\*.xls*")

Do While FName <> ""

Workbooks.Open Filename:=FPath & "\" & FName, ReadOnly:=True

For Each Sheet In ActiveWorkbook.Sheets

Sheet.Copy After:=ThisWorkbook.Sheets(1)

Next Sheet

Workbooks(FName).Close
FName = Dir()

Loop

Application.ScreenUpdating = True

End Sub
 
One additional line to mumps' code will do that ...
Rich (BB code):
Sub CombineWorkbooks_r2()
    Dim FName As String, FPath As String
    Dim desWB As Workbook
    Set desWB = ThisWorkbook
    Application.ScreenUpdating = False
    FPath = Worksheets("Combine Sheets").Cells(2, 2).Value
    FName = Dir(FPath & "\*.xls*")
    Do While FName <> ""
        Workbooks.Open Filename:=FPath & "\" & FName, ReadOnly:=True
        Sheets("Sheet1").Copy After:=desWB.Sheets(1)
        Workbooks(FName).Close False
        ActiveSheet.Name = Left(FName, (InStrRev(FName, ".")) - 1)
        FName = Dir()
    Loop
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Fantastic. To save me the agro as I’m trying to teach my self but is there a way to sort alphabetically
 
Upvote 0
What is the password for each workbook?
 
Upvote 0

Forum statistics

Threads
1,215,043
Messages
6,122,812
Members
449,095
Latest member
m_smith_solihull

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