Workbook to Workbook Data copy

jrtdcg

New Member
Joined
Dec 4, 2012
Messages
45
Hello Everyone,

Just curious if there is a way to copy from any open workbook to a new workbook? In other words...I'd like to have the ability to open any workbook of choice and run a macro from my personal quick access toolbar that copies data and paste values into another workbook without having to write the code to a specific workbook each time. Any ideas?

I have the code written to open a new workbook and save with a new name, but I'm stumped on the copy/paste portion of the code. Any help would be appreciated.

Thank you in advance!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
for the copy paste you could use the following:
Code:
sourceworkbook.sourceworksheet.cells.copy destination:= targetworkbook.targetworksheet.range("A1")

You can set the variable
Code:
dim sourceworkbook as workbook, targetworkbook as workbook
dim sourceworksheet as worksheet, targetworksheet as worksheet

The set the locations
Code:
Set sourceworkbook = activeworkbook
Set sourcesworksheet = activeworksheet
Set targetworkbook = workbook.open '(location details).  Or Workbook.add 
Set targetworksheet = targetworkbook.Sheetname  (If you have used workbook.add, it can be activesheet as that will be the active location.

The put the copy paste code in under and it should work. If not, step through the macro to see where it is falling over.
 
Upvote 0

Forum statistics

Threads
1,226,230
Messages
6,189,770
Members
453,568
Latest member
LaTwiglet85

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