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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

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