Link to home
Start Free TrialLog in
Avatar of mlagrange
mlagrangeFlag for United States of America

asked on

Shapes.PasteSpecial works in Office 2010, but not in 2013

Hello - a routine I use to copy Excel charts to PowerPoint slides works fine in Office 2010, but in Office 2013 gets an "Object Required" error on the following line of code:  

pptSlide.Shapes.PasteSpecial(DataType:=ppPasteEnhancedMetafile).Select

I have seen a few posts on this, but no solutions. Does anybody know the fix for this?

Thanks
Avatar of Professor J
Professor J

you must have decalred the pptSlide as Object, instead of ShapeRange
It could be because the paste operation isn't working prior to the Select method being used.

Try this to separate the two parts of the operation:

pptSlide.Shapes.PasteSpecial(DataType:=ppPasteEnhancedMetafile)
pptSlide.Shapes(1).Select

Open in new window


If it fails on the first line, IIRC the PasteSpecial works differently in VBA in Excel and PowerPoint and depending on which app is hosting the code, you may need to adapt.
Avatar of mlagrange

ASKER

Hello - sorry for leaving this hanging; I had to go deal with other projects.

I've tried the various things suggested in the articles you point to, but my situation is evidently different.

I hesitate to go into too much detail, because it's such a swamp. But here goes...

I'm an Access developer, and reasonably familiar with the Access object model, but not so much with Excel, and even less so with PowerPoint. I relied heavily on the kindess of EE responders.

This routine runs from an xlsm that contains a worksheet of safety awards by employee, that carry 3 levels of the emp's organizational hierachy ("L1", "L2", "L3"), and award descriptions for category and type. The xlsm charts these awards out into 3 pivot charts for award counts by Lx, with respective award categories, and award types.

The routine to copy & paste these 3 charts to PowerPoint actually iterates through: > the L1, then > each L2 w/in the L1, and then > each L3 w/in each L2. Each iteration copies the count, category and type charts to a new slide for the given Lx.  
 
I pretty much thumb-dicked my way into this arrangement where I have a pptx file I use as a template (a functional template, not an actual template). It has a header slide, and then a boilerplate slide that I've arranged with picture/shape placeholders for each chart. At the end of the routine, it is "Save As"'ed to a new file name.

I have reduced the code below to the first copy/paste of the boilerplate slide to the next new slide, and copying & pasting the first (L1) Award count chart from the xlsm to the placeholder on the pptx. I do it the same way at each Lx level, and each chart. It errors out right at this first L1 copy/paste.

If you're still here, I appreciate it  :-)

Option Explicit

Public Function L1toPP(pptPresent As PowerPoint.Presentation)

    'On Error GoTo PROC_ERR
    
    Dim wksAwrds As Worksheet, pvtAwrds As PivotTable, ptfAwrds As PivotField, ptiAwrds As PivotItem, chtAwrds As Excel.ChartObject
    Dim dblTarget As Double, txtTarget As String
    'Dim wksOutside As Worksheet, pvtOutside As PivotTable, dblOutside As Double, txtOutside As String
                        
    '-- L1 (no iteration through rpt filter needed)
    Set wksAwrds = ThisWorkbook.Worksheets("L1 Chart")
    Set pvtAwrds = wksAwrds.PivotTables("pvtL1")
    
    '-- set the L1 Chart AwardQtr to the selected value on the L2 Chart
    pvtAwrds.PivotFields("AwardQtr").CurrentPage = ThisWorkbook.Worksheets("L2 Chart").PivotTables("pvtL2").PivotFields("AwardQtr").CurrentPage.Name
    
    Set chtAwrds = wksAwrds.ChartObjects(1)
    
    '-- set the 2nd slide into an object variable, for ref'ing the positions & measurements later
    Dim pptSlideTmp As PowerPoint.Slide
    Set pptSlideTmp = pptPresent.Slides(2)
    
    '-- copy the 2nd slide in the ppt template for the next new slide (could have just copied [pptSlideTmp] at this point?
    Dim pptSlideNew As PowerPoint.Slide
    pptPresent.Slides(2).Copy
    pptPresent.Slides.Paste (pptPresent.Slides.Count + 1)
    Set pptSlideNew = pptPresent.Slides(pptPresent.Slides.Count)
    pptSlideNew.Select
    
    '-- set the slide title
    pptSlideNew.Shapes("ttlLvl").TextFrame.TextRange.Text = "GREF"
    
    'Copy the chart and paste it into the PowerPoint as a Metafile Picture
    chtAwrds.Select
    chtAwrds.Chart.ChartArea.Copy
    
    '-- delete the placeholder for the Awards chart
    pptSlideNew.Shapes("picAwrds").Delete
    
    '>>> this is the line that errors out with "Object requried"
    pptSlideNew.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select
    
    Dim pptShpAwrds As PowerPoint.Shape
    Set pptShpAwrds = pptSlideNew.Shapes(pptSlideNew.Shapes.Count)
        
    'Adjust the positioning of the Chart on Powerpoint Slide
    pptShpAwrds.Left = pptSlideTmp.Shapes("picAwrds").Left
    pptShpAwrds.Top = pptSlideTmp.Shapes("picAwrds").Top
    pptShpAwrds.Height = pptSlideTmp.Shapes("picAwrds").Height
    pptShpAwrds.Width = pptSlideTmp.Shapes("picAwrds").Width
    
    '-- similar code continues for award category & type charts...

End Function

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jamie Garroch (MVP)
Jamie Garroch (MVP)
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
YES!  THANK YOU!