Bonjour,
Voici deux petites macro simples représentatives de mon problème.
La première, initChart, crée des valeurs dans la feuille, crée une chart vide et protège la feuille.
Certaines cellules sont déprotégées.
la seconde, Chart, recopie des valeurs dans la feuille et trace une courbe.
Les macro sont ok sous Excel 2003.
J'ai une erreur en 2007 à la ligne "Item.Delete" de la macro "Chart".
Lorsque je commente la ligne de initChart qui protège la feuille, c'est OK.
J'en déduit que les protections concernant les Charts sont traitées différemment sous 2007 que 2003, mais je ne sais pas pourquoi et comment résoudre mon problème proprement.
J'ai essayé un "ActiveSheet.ChartObjects(1).Locked = False" mais ça ne change rien...
Merci d'avance pour vos eclaircissements,
Stabilo
PS: Problème reproduit sous XP 64 et Vista 32
Sub initChart()
ActiveSheet.Cells(1, 1) = 0
ActiveSheet.Cells(2, 1) = 1
ActiveSheet.Cells(3, 1) = 2
ActiveSheet.Cells(5, 2) = 0
ActiveSheet.Cells(6, 2) = 2
ActiveSheet.Cells(7, 2) = 3
ActiveSheet.Cells(5, 2).Locked = False
ActiveSheet.Cells(6, 2).Locked = False
ActiveSheet.Cells(7, 2).Locked = False
MySheetName = ActiveSheet.name
Range(ActiveSheet.Cells(1, 3), ActiveSheet.Cells(15, 7)).Select
With Selection
.MergeCells = True
End With
Charts.Add
ActiveChart.DisplayBlanksAs = xlZero
ActiveChart.PlotVisibleOnly = False
ActiveChart.ChartType = xlLine
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
ActiveChart.Location Where:=xlLocationAsObject, name:=MySheetName
areaoffset = 5
size_X_pixel = ActiveSheet.Cells(1, 1).Width * 5 - 2 * areaoffset
size_Y_pixel = ActiveSheet.Cells(1, 1).Height * 15 - 2 * areaoffset
With ActiveSheet.ChartObjects(1)
.Width = size_X_pixel
.Height = size_Y_pixel
.Left = ActiveSheet.Cells(rowpos + 1, 3).Left + areaoffset
.Top = ActiveSheet.Cells(rowpos + 1, 3).Top + areaoffset
End With
ActiveSheet.Protect Contents:=True, Scenarios:=True, UserInterfaceOnly:=True
End Sub
Sub Chart()
ActiveSheet.Cells(1, 2) = ActiveSheet.Cells(5, 2)
ActiveSheet.Cells(2, 2) = ActiveSheet.Cells(6, 2)
ActiveSheet.Cells(3, 2) = ActiveSheet.Cells(7, 2)
MySheetName = ActiveSheet.name
For Each Item In ActiveSheet.ChartObjects(1).Chart.SeriesCollection
Item.Delete
Next
ActiveSheet.ChartObjects(1).Chart.SeriesCollection .NewSeries
ActiveSheet.ChartObjects(1).Chart.SeriesCollection (1).XValues = "=" & MySheetName & "!R1C1:R3C1"
ActiveSheet.ChartObjects(1).Chart.SeriesCollection (1).Values = "=" & MySheetName & "!R1C2:R3C2"
ActiveSheet.ChartObjects(1).Chart.SeriesCollection (1).name = "My curve"
End Sub
Voici deux petites macro simples représentatives de mon problème.
La première, initChart, crée des valeurs dans la feuille, crée une chart vide et protège la feuille.
Certaines cellules sont déprotégées.
la seconde, Chart, recopie des valeurs dans la feuille et trace une courbe.
Les macro sont ok sous Excel 2003.
J'ai une erreur en 2007 à la ligne "Item.Delete" de la macro "Chart".
Lorsque je commente la ligne de initChart qui protège la feuille, c'est OK.
J'en déduit que les protections concernant les Charts sont traitées différemment sous 2007 que 2003, mais je ne sais pas pourquoi et comment résoudre mon problème proprement.
J'ai essayé un "ActiveSheet.ChartObjects(1).Locked = False" mais ça ne change rien...
Merci d'avance pour vos eclaircissements,
Stabilo
PS: Problème reproduit sous XP 64 et Vista 32
Sub initChart()
ActiveSheet.Cells(1, 1) = 0
ActiveSheet.Cells(2, 1) = 1
ActiveSheet.Cells(3, 1) = 2
ActiveSheet.Cells(5, 2) = 0
ActiveSheet.Cells(6, 2) = 2
ActiveSheet.Cells(7, 2) = 3
ActiveSheet.Cells(5, 2).Locked = False
ActiveSheet.Cells(6, 2).Locked = False
ActiveSheet.Cells(7, 2).Locked = False
MySheetName = ActiveSheet.name
Range(ActiveSheet.Cells(1, 3), ActiveSheet.Cells(15, 7)).Select
With Selection
.MergeCells = True
End With
Charts.Add
ActiveChart.DisplayBlanksAs = xlZero
ActiveChart.PlotVisibleOnly = False
ActiveChart.ChartType = xlLine
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
ActiveChart.Location Where:=xlLocationAsObject, name:=MySheetName
areaoffset = 5
size_X_pixel = ActiveSheet.Cells(1, 1).Width * 5 - 2 * areaoffset
size_Y_pixel = ActiveSheet.Cells(1, 1).Height * 15 - 2 * areaoffset
With ActiveSheet.ChartObjects(1)
.Width = size_X_pixel
.Height = size_Y_pixel
.Left = ActiveSheet.Cells(rowpos + 1, 3).Left + areaoffset
.Top = ActiveSheet.Cells(rowpos + 1, 3).Top + areaoffset
End With
ActiveSheet.Protect Contents:=True, Scenarios:=True, UserInterfaceOnly:=True
End Sub
Sub Chart()
ActiveSheet.Cells(1, 2) = ActiveSheet.Cells(5, 2)
ActiveSheet.Cells(2, 2) = ActiveSheet.Cells(6, 2)
ActiveSheet.Cells(3, 2) = ActiveSheet.Cells(7, 2)
MySheetName = ActiveSheet.name
For Each Item In ActiveSheet.ChartObjects(1).Chart.SeriesCollection
Item.Delete
Next
ActiveSheet.ChartObjects(1).Chart.SeriesCollection .NewSeries
ActiveSheet.ChartObjects(1).Chart.SeriesCollection (1).XValues = "=" & MySheetName & "!R1C1:R3C1"
ActiveSheet.ChartObjects(1).Chart.SeriesCollection (1).Values = "=" & MySheetName & "!R1C2:R3C2"
ActiveSheet.ChartObjects(1).Chart.SeriesCollection (1).name = "My curve"
End Sub