VBA Code copy in sheet from closed workbook.

jakobt

Active Member
Joined
May 31, 2010
Messages
337
Have a open workbook called Summary.xlsx. But this could in principle be all current selected workbooks.

Want to create a macro:
1) to open another workbook called Accounts, saved in folder C:\
2) Copy sheet called MD in workbook called Accounts
3) Insert it in workbook summary (or any other workbook which was initially selected.
4) Closed workbook called Accounts
5) Select cell A1 in The first selected workbook.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try this
- path in red should be full path to the file

Code:
Sub CopySheet()
    Application.ScreenUpdating = False
    Dim acs As Workbook, Book As Workbook
    Set Book = ActiveWorkbook
[COLOR=#a9a9a9]'1) to open another workbook called Accounts, saved in folder C:\[/COLOR]
    Set acs = Workbooks.Open("[COLOR=#ff0000]C:\Accounts.xlsx[/COLOR]")
[COLOR=#a9a9a9]'2) Copy sheet called MD in workbook called Accounts[/COLOR]
[COLOR=#a9a9a9]'3) Insert it in workbook summary (or any other workbook which was initially selected[/COLOR]
    acs.Sheets("MD").Copy before:=Book.Sheets(1)
[COLOR=#a9a9a9]'4) Closed workbook called Accounts (without saving)[/COLOR]
    acs.Close False
[COLOR=#a9a9a9]'5) Select cell A1 in The first selected workbook[/COLOR]
    Range("A1").Activate
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,316
Members
452,634
Latest member
cpostell

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