Macro to Copy a worksheet from an unopened workbook to a worksheet in an opened workbook

pincivma

Board Regular
Joined
Dec 12, 2004
Messages
206
HI there

I believe that is easily solved. All I want is an easy macro to do following. Any help would be appreciated.

I have a workbook that is stored in "C:\users\Documents\my name\ Book1" This workbook is not opened
I have an open workbook that I want to store the macro.
So what the macro does is open the Book1 workbook copy all the contents from Sheet1 to the opened workbook in sheet1

Note: The open workbook could have different file names.

Thanks
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
This macro assumes the source file has an "xlsx" extension. Change it to suit your needs.
Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim wkbDest As Workbook
    Dim wkbSource As Workbook
    Set wkbDest = ThisWorkbook
    Set wkbSource = Workbooks.Open("C:\users\Documents\my name\Book1.[COLOR="#FF0000"]xlsx[/COLOR]")
    With wkbSource
        .Sheets("Sheet1").UsedRange.Copy wkbDest.Sheets("Sheet1").Cells(1, 1)
        .Close savechanges:=False
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,974
Messages
6,175,737
Members
452,667
Latest member
vanessavalentino83

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