troubleshooting Question

VBA copying images to PPT

Avatar of montrof
montrofFlag for United States of America asked on
Microsoft ExcelMicrosoft PowerPoint
3 Comments1 Solution507 ViewsLast Modified:
I have been using the below function to copy images to excel for a long time.  I have always used the named range to copy the chart.  Now I want to change it so that it selects the actual chart and not the range around the chart.  

This is the code I was using

 
Range(strRange).Copy
  Range("A1").Select
  Debug.Print Err.Description

This is what I want to change it to

     
ActiveWorkbook.Range("Excel" & strRange).Select
     ActiveSheet.ChartObjects(strRange).Activate
     ActiveChart.ChartArea.Copy
     Range("A1").Select

it seems to error out at the range select I am just using the range select to make sure I am on the right sheet that the chart is loacted on .  

Here is the full function


Function CopyRangeToPPT(oPPTApp As PowerPoint.Application, intSlideNum As Integer, intLeft As Integer, intWidth As Integer, intHeight As Integer, intTop As Integer, strRange As String) As String
    Dim shShape As Object, strError As String

    'delete shape if it exists on slide
    On Error Resume Next
    oPPTApp.ActivePresentation.Slides("Slide_" & strRange).Shapes("ExcelSlide_" & strRange).Delete
    If Err.Number <> 0 Then CopyRangeToPPT = Err.Number & " " & Err.Description & ": " & strRange & vbCrLf
    Err.Clear
    ' Select the range then copy it.

    On Error GoTo 0
     ActiveWorkbook.Range("Excel" & strRange).Select
     ActiveSheet.ChartObjects(strRange).Activate
     ActiveChart.ChartArea.Copy
     Range("A1").Select
    
'        ActiveSheet.ChartObjects("strRange").Activate
'        ActiveChart.ChartArea.Copy
'
'
'    ActiveSheet.ChartObjects("Slide1").Activate
'    ActiveChart.ChartArea.Copy
'
    

'    Range(strRange).Copy
'    Range("A1").Select
'    Debug.Print Err.Description

    ' Paste the range

    Set shShape = oPPTApp.ActivePresentation.Slides(intSlideNum).Shapes.PasteSpecial(ppPasteEnhancedMetafile)

    ''    oPPTApp.Run ("ResizeShapeSize")

    ' Align the pasted range

    With shShape
        .LockAspectRatio = 0
        .Left = intLeft
        .Top = intTop
        .Width = intWidth
        .Height = intHeight
        .Name = "ExcelSlide_" & strRange
    End With
    
   
End Function


Thanks,
Montrof
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros