1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| Sub ExecMacro()
Dim fso, F, wb, oFold, Application, sPath
Set fso = CreateObject("Scripting.FileSystemObject")
sPath = "C:\toto\" 'Application.ActiveWorkbook.Path '& "\toto\"
If Right(spath, 1) <> "\" Then sPath = sPath & "\"
Set oFold = fso.GetFolder(sPath)
Set Application = CreateObject("Excel.Application")
For Each F In oFold.Files
If Ucase(Right(F.Name, 4)) = ".XLS" Then
Set wb = Application.Workbooks.Open(F.Path)
DoWork wb
wb.Close True
End If
Next
End Sub
Sub DoWork(wb)
With wb
'Dim wb, myrange, mysheetname
Set wb = Application.ActiveWorkbook
Range("a16").Select
Selection.CurrentRegion.Select
myrange = Selection.Address
mysheetname = ActiveSheet.Name
ActiveSheet.ChartObjects.Add(300, 250, 600, 400).Select
Application.CutCopyMode = False
'ActiveChart.ChartWizard _
'Source=Sheets(mysheetname).Range(myrange), _
'Gallery=xlColumnStacked, Format=4, PlotBy=xlColumns, _
'CategoryLabels=1, SeriesLabels=1, HasLegend=1, _
'Title="", CategoryTitle="", _
'ValueTitle="", ExtraTitle=""
ActiveChart.ChartWizard Sheets(mysheetname).Range(myrange), xlColumnStacked, 4, xlColumns, 1, 1, 1, "", "", "", ""
End With
End Sub |
Partager