how to run a macro on a group of files and merge results in a masterfile?

flemak

New Member
Joined
Dec 2, 2016
Messages
2
hey, I have a macro that creates a diagram and copies it to another file.. my code looks like this one:

'create diagram:

ActiveSheet.Shapes.AddChart2(227, xlLine).Select
ActiveChart.SetSourceData Source:=Range( _
"'Tabelle1'!$F$3:$F$722")

ActiveChart.FullSeriesCollection(1).XValues = _
"='Tabelle1'!$B$3:$B$722"


'copy diagram:

ActiveChart.ChartArea.Select
Application.CutCopyMode = False
ActiveChart.ChartArea.Copy
Windows("Masterfile Diagramm.xlsx").Activate
ActiveSheet.ChartObjects("summary").Select
ActiveChart.Paste


I want to run this code on a group of Excel files (e.g. file1, file2, file3 and file4) without editing every single workbook of every file (without Auto_Open() or Workbook_Open) and also by referencing to the files with a loop.
Maybe similar like this(?):


dim i as integer
for i=1 to 20
<code class="vb plain">workbooks.open filename:= </code><code class="vb string">"file"</code> <code class="vb plain">& i</code>

<code class="vb plain">next i</code>




I cannot figure out a way to do it without writing a sub Workbook_open() macro in every file which is too much work if I have 50 or more files to run the macro on.

Thanks for your help and have a good weekend!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Forum statistics

Threads
1,214,653
Messages
6,120,752
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