Question

Seems there is some bug. Can't resolve this problem, all code is running fine and I am able to see the AutoShape is getting copied from Excel file but it is not adding it to PowerPoint. Popping up an error Run-time error '-2147188160(80048240) View.Pastespecial : Invalid Request. The specified data type is unavailable

If Range("H" & i).Value = 1 And Range("B" & i).Value = "FRONT" Then
    objPPT.Presentations(1).Slides(9).Select
    objPPT.ActiveWindow.View.PasteSpecial DataType:=ppPasteEnhancedMetafile
Was it helpful?

Solution

Your code will be faster and possibly more reliable if you don't rely on selecting anything:

With objPPT.Slides(9).Shapes
    Set objShape = .PasteSpecial(ppPasteEnhancedMetafile)(1)
    With objShape
       ' set coordinates and such here
    End With
End With

As to why you're getting the error message, try stopping the code after you've put something on the clipbard. Then switch to PowerPoint, use Paste Special to see what paste options are available. If EMF isn't one of them, that's your problem ... you're not putting anything in EMF format on the clipboard.

OTHER TIPS

I had a similar issue, but I found a different solution; it may be specific to what I was doing though.

I setup a program where I would:

  1. (manual) Copy an entire webpage that was a report on several performance metrics
  2. (manual) Pasted it in to excel
  3. Run the program to extract the values I want and then clear contents of the sheet I pasted them on.

Eventually after many tests, it would fail with this same automation error when I tried to access the sheet:

Sheets("PDX Paste").Activate

I was able to activate every other sheet except that particular one, even using the index value instead of the direct name reference. After googling to no success I found out that the copy and paste from the website was also pasting invisible controls. When I found this out I had 1,300+ shapes when I only expected 1 (the button I use to trigger the program). It was actually only apparent when a glitch - presumably due to so much memory being used to store these controls - displayed for a few seconds.

I ran the following code independently and then appended it to the end of my program when I do the cleanup of the data. The code goes through the sheet and deletes any shape that isn't the same type as my button. It would have to be adapted if the shapes you want to delete are the same type as the shapes you want to keep. It also becomes simpler if you don't have any shapes to keep.

Dim wsh As Worksheet
Set wsh = ActiveSheet

Dim i As Integer

For i = wsh.Shapes.Count To 1 Step -1
    If wsh.Shapes(i).Type <> wsh.Shapes("UpdateDataButton").Type Then
        wsh.Shapes(i).Delete
    End If
Next i

I'm not sure this would solve this problem, but hopefully this can help others and prevent loss of time figuring out what may be causing this relatively vague error message.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top