VBA - copy sheet from another workbook to current workbook

macroos

New Member
Joined
May 30, 2018
Messages
45
Hi,

I am trying to create a macro that can copy a sheet from another workbook to the workbook that I'm currently using.

I have both workbooks in the same folder.
Copy Workbook1.xlsx sheet named "Schedule" onto test.xlsm

Is there something wrong with the code that I'm using below:

Code:
Sub MoveSheets()
    Windows("Workbook1.xlsx").Activate
    Sheets("Schedule").Select
    Sheets("Schedule").Copy Before:=Workbooks("test.xlsm").Sheets(1)
End Sub

And if I want to be copying sheets from several different workbooks (Workbook2, Workbook3, and etc), do I just keep adding the same three lines and changing the file names?
 
Last edited:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
shorter version

Code:
Sub MoveSheets()
    Workbooks("Workbook1.xlsx").Sheets("Schedule").Copy Before:=Workbooks("test.xlsm").Sheets(1)
End Sub


Both workooks need to be open.
 
Last edited:
Upvote 0
Thank you.

Is there a way to make the Workbook1 automatically open and after it finishes copying, it will automatically close?
 
Upvote 0
Never mind.

I used:

Workbooks.Open Filename:="....Workbooks1.xlsx"
Workbooks("Workbooks1.xlsx").Sheets("Schedule").Copy Before:=Workbooks("test.xlsm").Sheets(1)
Workbooks("Workbooks1.xlsx").Close savechanges:=False
 
Upvote 0
Never mind.

I used:

Workbooks.Open Filename:="....Workbooks1.xlsx"
Workbooks("Workbooks1.xlsx").Sheets("Schedule").Copy Before:=Workbooks("test.xlsm").Sheets(1)
Workbooks("Workbooks1.xlsx").Close savechanges:=False

The KISS method Keep It Short & Simple.
 
Upvote 0

Forum statistics

Threads
1,215,764
Messages
6,126,748
Members
449,335
Latest member
Tanne

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