我有以下代码:
Sub Export_Allcahrts_ppt()
Dim mypowerpoint As PowerPoint.Application
Dim mypowerpoint_pres As PowerPoint.Presentation
Dim myslide As PowerPoint.Slide
Dim mychart As ChartObject
Set mypowerpoint = New PowerPoint.Application
mypowerpoint.Visible = msoTrue
Set mypowerpoint_pres = mypowerpoint.Presentations.Add
Set myslide = mypowerpoint_pres.Slides.Add(1, ppLayoutBlank)
For Each mychart In Sheet1.ChartObjects
mychart.Copy
myslide.Shapes.PasteSpecial ppPasteBitmap
With myslide.Shapes(myslide.Shapes.Count)
.Top = 100
.Height = 200
.Left = 30
End With
Next
End Sub
如何在Excel中选择特定的图表,例如工作表1中的图表1,工作表2中的图表2,并将它们粘贴到PowerPoint的一张幻灯片上?
这将遍历工作簿中的所有工作表,然后只需检查您要查找的图表。 如果图表的名称类似于工作表 1 上的 chart1,则.....
Set wb as activeworkbook
For Each sht In wb.Worksheets
For Each cht In sht.ChartObjects
'check for name of chart, if statements or a case select statement.
if cht.name = "Chart" & sht.index then
'Copy to PPT
end if
Next cht
Next sht