1

I have been working on automating the copying of editable charts from an excel workbook to a PowerPoint presentation through VBA. I got a lot of help through this link Using VBA to Paste Excel Chart with Data into PowerPoint which has sorted the copy-pasting bit.

Sub CopyChartSlide2()
Application.ScreenUpdating = False
   
   
  Dim newPowerPoint As PowerPoint.Application
  Dim activeSlide As PowerPoint.Slide
  Dim cht1 As Excel.ChartObject
  Dim Data As Excel.Worksheet
  Dim pptcht1 As PowerPoint.Shape
  Dim iLoopLimit As Long
  Dim OpenPptDialogBox As Object
  Dim SlideIndex As Long
 

  Application.ScreenUpdating = False

  'Look for existing instance
 
     
     Set newPowerPoint = CreateObject("PowerPoint.Application")
   Set OpenPptDialogBox = newPowerPoint.FileDialog(msoFileDialogOpen)
   If OpenPptDialogBox.Show = -1 Then
    newPowerPoint.Presentations.Open (OpenPptDialogBox.SelectedItems(1))
    End If
        
    Set activeSlide = newPowerPoint.ActivePresentation.Slides(1)
       
    SlideIndex = 1

  Set Data = Worksheets("Slide2")

  Set cht1 = Data.ChartObjects("Chart1")
 
  cht1.Copy

  newPowerPoint.CommandBars.ExecuteMso "PasteExcelChartDestinationTheme"

  DoEvents

  On Error Resume Next
  Do
    DoEvents
    Set pptcht1 = activeSlide.Shapes(activeSlide.Shapes.Count)
    If Not pptcht1 Is Nothing Then Exit Do
    iLoopLimit = iLoopLimit + 1
    If iLoopLimit > 100 Then Exit Do
  Loop
  On Error GoTo 0

  Debug.Print "iLoopLimit = " & iLoopLimit

  With pptcht1
    .Left = 103.68
    .Top = 84.24
  End With

  iLoopLimit = 0
 
  AppActivate newPowerPoint.Caption
  Set activeSlide = Nothing
  Set newPowerPoint = Nothing

Application.ScreenUpdating = True

End Sub

However, when the charts get pasted, it embeds the entire workbook instead of just the worksheet. Since I am working with a workbook of around 20 sheets, and each time a chart is pasted into the presentation, the entire workbook gets embedded and since there are many charts, it makes the PPT heavy and makes the process very slow. Is there a way to only embed the worksheet that is relevant to the chart?

2
  • 1
    Does the chart need to be an editable chart, or can you use CopyAsPicture to put an image of the chart into PowerPoint instead? If not, you might need to create a macro to extract the chart & worksheet to a temporary workbook, and embed that instead Commented May 11, 2021 at 14:03
  • No, it needs to be an editable chart Commented May 11, 2021 at 14:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.