Copy sheets from closed workbook

BarneyLTD

New Member
Joined
Sep 27, 2017
Messages
27
Hi all, back again with another ask.

I have tried the below code (with a slight mod to try and pull the whole sheet rather than the range) to try and call up a workbook (name changes so need to be able to select from file explorer), copy sheets 1-4 and paste in the original workbook that the macro was run from, at the end. this can be referenced if needed and is called List Creator v2.xlsm - can anyone help out? I can't get it to work.

Code:
Sub CopySheet()Dim FileFilter As String
Dim FileName As String
Dim SrcWkb As Workbook
FileFilter = "All Excel Files,*.xla;*.xls;*.xlt,All Files, *.*"
FileName = Application.GetOpenFilename(FileFilter)
If FileName = "False" Then Exit Sub
Set SrcWkb = Workbooks.Open(FileName)
SrcWkb.Sheets(1).UsedRange.Copy ThisWorkbook.ActiveSheet.Range("A1")
SrcWkb.Close False
End Sub

Cheers :)
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
When you say "pull the whole sheet", do you mean actually copy the worksheets, or just the data from the worksheets?
 
Upvote 0
Then you can replace this:

Code:
SrcWkb.Sheets(1).UsedRange.Copy ThisWorkbook.ActiveSheet.Range("A1")

with something like this:

Code:
SrcWkb.Sheets(Array(1, 2, 3, 4)).Copy Before:=ThisWorkbook.Sheets(1)
 
Upvote 0

Forum statistics

Threads
1,223,702
Messages
6,173,936
Members
452,539
Latest member
delvey

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