Proposition
Sub fond()
With ActiveSheet.Shapes("Graphique 2")
gl = .Left: gt = .Top: gw = .Width: gh = .Height
End With
ActiveSheet.ChartObjects("Graphique 2").Activate
With ActiveChart
With .PlotArea
pl = .Left: pt = .Top: pw = .Width: ph = .Height
End With
xmin = .Axes(xlCategory).MinimumScale: xmax = .Axes(xlCategory).MaximumScale
ymin = .Axes(xlValue).MinimumScale: ymax = .Axes(xlValue).MaximumScale
End With
ActiveSheet.Shapes.Range(Array("hg")).Select
With Selection.ShapeRange
.Left = gl + pl
.Top = gt + pt
.Width = pw * ([mx] - xmin) / (xmax - xmin)
.Height = ph * (ymax - [my]) / (ymax - ymin)
.ZOrder msoSendToBack
End With
ActiveSheet.Shapes.Range(Array("bg")).Select
With Selection.ShapeRange
.Left = gl + pl
.Top = gt + pt + ph * (ymax - [my]) / (ymax - ymin)
.Width = pw * ([mx] - xmin) / (xmax - xmin)
.Height = ph * ([my] - ymin) / (ymax - ymin)
.ZOrder msoSendToBack
End With
ActiveSheet.Shapes.Range(Array("hd")).Select
With Selection.ShapeRange
.Left = gl + pl + pw * ([mx] - xmin) / (xmax - xmin)
.Top = gt + pt
.Width = pw * (xmax - [mx]) / (xmax - xmin)
.Height = ph * (ymax - [my]) / (ymax - ymin)
.ZOrder msoSendToBack
End With
ActiveSheet.Shapes.Range(Array("bd")).Select
With Selection.ShapeRange
.Left = gl + pl + pw * ([mx] - xmin) / (xmax - xmin)
.Top = gt + pt + ph * (ymax - [my]) / (ymax - ymin)
.Width = pw * (xmax - [mx]) / (xmax - xmin)
.Height = ph * ([my] - ymin) / (ymax - ymin)
.ZOrder msoSendToBack
End With
Cells(1, 1).Select
End Sub
sachant que j'ai créé au préalable 4 rectangles appelés hg, bd, hg, bg (haut droit, bas droit, haut gauche, bas gauche)
le seul soucis que j'ai, ce sont les largeurs des axes que je n'ai pas réussi à identifier ...