简体   繁体   中英

VBA - How to select specific charts in excel and paste them on single slide in power point

I have the following code:

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

How to select specific charts like chart 1 in sheet 1, chart 2 in sheet 2 in excel and paste them on a single slide in powerpoint?

This will iterate through all sheets in workbook, then just check for the charts you are looking for. If the charts are named like chart1 on sheet1, then.....

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM