2011-10-12 144 views
1

我使用创建幻灯片的Excel脚本。 在幻灯片上,我想显示图表的图例,但不显示图表的其余部分。使用VBA将图表的图形复制到Powerpoint

这里是我的代码的摘录:

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”也不起作用。

回答

2

我不认为你只能复制图例,或删除绘图区 - 或删除它的所有内容(系列),而不消失图例。

你可以做的是使该地块面积非常小,并且隐藏它的传奇背后:

With ActiveChart 
    .Axes(xlCategory).Delete 
    .Axes(xlValue).Delete 
    .PlotArea.ClearFormats 
    .Axes(xlValue).MajorGridlines.Delete 
    ' Make it small 
    With .PlotArea 
     .Width = 0 
     .Height = 0 
    End With 
    ' Move the legend on top of it 
    With .Legend 
     .Left = 1 
     .Top = 1 
    End With 
End With 

如果你愿意,你就可以减少您的图表区域的大小,使其适合紧密地围绕传奇。

+0

谢谢,这是一个好主意! – reggie

+0

+1良好的解决方法。 – brettdj

相关问题