使用 VBA 将图表图例复制到 Powerpoint
我正在编写一个创建 powerpoint 幻灯片的 Excel 脚本。 在幻灯片上,我想显示图表的图例,但不显示图表的其余部分。
以下是我的代码摘录:
With Sheets("data")
Set bereich = Range(.Cells(Daty + 1, 3), .Cells(Daty + 2 + UBound(SubCategories), Datx + UBound(anzahl, 1)))
Set dia = .ChartObjects.Add(10, 800, 650, 400)
.ChartObjects(dia.Name).Activate
dia.Name = "ideaspersubcatstatus"
.Shapes(dia.Name).Left = Range(.Cells(intSubCat + 3, 1), .Cells(intSubCat + 3, 1)).Left
.Shapes(dia.Name).Top = Range(.Cells(intSubCat + 3, 1), .Cells(intSubCat + 3, 1)).Top
End With
With ActiveChart
.ChartType = xlBarStacked
.SetSourceData Source:=bereich, PlotBy:=xlColumns
.HasLegend = True
.PlotArea.Interior.ColorIndex = xlNone
.Axes(xlCategory).TickLabelSpacing = 1
.ChartArea.Border.LineStyle = 0
.Axes(xlValue).MajorGridlines.Border.LineStyle = xlDot
End With
我需要将图表的图例复制到 powerpoint,或者在将其复制到 Powerpoint 之前从图表中删除除图例之外的所有内容。
With .Slides(9)
'copy graph from Excel
Workbooks("data.xls").Worksheets("data").ChartObjects("ideaspersubcatstatus").Copy
'paste graph into Powerpoint
.Shapes.Paste
End With
不支持“.PlotArea.Delete”。 “.ChartObjects(1).Legend.Copy”也不起作用。
I work on an excel script that creates powerpoint slides.
On a powerpoint slide, I want to show the legend of a chart, but not the rest of the chart.
Here is an excerpt of my code:
With Sheets("data")
Set bereich = Range(.Cells(Daty + 1, 3), .Cells(Daty + 2 + UBound(SubCategories), Datx + UBound(anzahl, 1)))
Set dia = .ChartObjects.Add(10, 800, 650, 400)
.ChartObjects(dia.Name).Activate
dia.Name = "ideaspersubcatstatus"
.Shapes(dia.Name).Left = Range(.Cells(intSubCat + 3, 1), .Cells(intSubCat + 3, 1)).Left
.Shapes(dia.Name).Top = Range(.Cells(intSubCat + 3, 1), .Cells(intSubCat + 3, 1)).Top
End With
With ActiveChart
.ChartType = xlBarStacked
.SetSourceData Source:=bereich, PlotBy:=xlColumns
.HasLegend = True
.PlotArea.Interior.ColorIndex = xlNone
.Axes(xlCategory).TickLabelSpacing = 1
.ChartArea.Border.LineStyle = 0
.Axes(xlValue).MajorGridlines.Border.LineStyle = xlDot
End With
I either need to copy the legend of the graph to powerpoint, or remove everything but the legend from the chart before I copy it to Powerpoint.
With .Slides(9)
'copy graph from Excel
Workbooks("data.xls").Worksheets("data").ChartObjects("ideaspersubcatstatus").Copy
'paste graph into Powerpoint
.Shapes.Paste
End With
".PlotArea.Delete" is not supported. ".ChartObjects(1).Legend.Copy" did not work, either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您不能仅复制图例,或删除绘图区域 - 或删除其所有内容(系列)而不会使图例消失。
您可以做的就是使绘图区域非常小,并将其隐藏在图例后面:
如果需要,您可以减小图表区域的大小,使其紧贴在图例周围。
I don't think you can copy only the legend, or delete the plot area -- or delete all of its contents (series) without the legend disappearing.
What you can do is make the plot area really small, and hide it behind the legend:
If you want, you can then reduce the size of your Chart area so that it fits snuggly around the legend.