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 Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,215,325
Messages
6,124,252
Members
449,149
Latest member
mwdbActuary

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