Get data from any given filename

Maagaard

Board Regular
Joined
Apr 16, 2013
Messages
70
Hi,

I need to create a macro that can get data from any given workbook, into a given workbook.

My problem is, that the "source" workbook will not be the same from time to time, eventhough it follows the same structure. Is there a way to get data from any given workbook, that is open for example?

I'm thinking something like:

Workbook("destnation").Sheets("DestinationSheet").Cells(1, 1) = Workbook(open workbook).Sheets("Sheet1").Cells(2,3)

Is there a possible way to do this?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi,
You can access other open workbooks by number:

Workbooks("Destination").... = Workbooks(2)...

This isn't really a solution since I presume you still need to have some logic about which, precisely, other open workbook you want to access. If it is always the last workbook opened you could go with the count:
Workbooks(Workbooks.Count) ....

I think in general you really should have some more structure. There should be some way to identify the workbook you want to use other than just assuming its another open workbook (i.e., names ranges in the workbook, some pattern in the naming scheme, or some way for the user to do this (perhaps a userform that let's the user select the workbook to copy from in a listbox).
 
Upvote 0
Hi,
You can access other open workbooks by number:

Workbooks("Destination").... = Workbooks(2)...

This isn't really a solution since I presume you still need to have some logic about which, precisely, other open workbook you want to access. If it is always the last workbook opened you could go with the count:
Workbooks(Workbooks.Count) ....

I think in general you really should have some more structure. There should be some way to identify the workbook you want to use other than just assuming its another open workbook (i.e., names ranges in the workbook, some pattern in the naming scheme, or some way for the user to do this (perhaps a userform that let's the user select the workbook to copy from in a listbox).
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,749
Members
448,989
Latest member
mariah3

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