VBA run-time error “7” when naming xlXY ScatterLines chart

前提是你 提交于 2020-01-06 03:15:31

问题


I'm running a code that requires me to name a chart so I can refer back to it later. The code I use for this is:

Sheets("Summary").Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterLines
With ActiveChart
    .Name = "energy distribution chart"
End With

I've tried just naming the chart not using the with... as in:

ActiveChart.Name = "energy distribution chart"

Doesn't work also. Whenever the code runs at that line I get a "run-time error 7 - Out of memory". I've tried putting this code so that it starts to run in a new macro in a new module but it still always gets that error 7 - 3 lines into a new piece of code! I have no idea what's going on. Help?

Edit: Following to mehow's answer, how do I then re-select the chart?

I've tried:

With Worksheets("Summary").ChartObjects("energy distribution chart").Chart(1)
    .SeriesCollection(sheet_number - 1).XValues = Worksheets(sheet_number).Range(Sheets(sheet_number).Cells(1, 7), Sheets(sheet_number).Cells(i4, 7))
    .SeriesCollection(sheet_number - 1).Values = Worksheets(sheet_number).Range(Sheets(sheet_number).Cells(1, 8), Sheets(sheet_number).Cells(i4, 8))
End With

Which doesn't seem to work... .. hm. I've also tried getting rid of the (1) next to charts. Yep. No idea.


回答1:


Chart it's an embed object. If you want to change of the object ( not chart itself ) then

ActiveChart.Parent.Name = "chart name"

See MSDN for more details



来源:https://stackoverflow.com/questions/20973149/vba-run-time-error-7-when-naming-xlxy-scatterlines-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!