VBA Office2010 Shapes.PasteSpecial fails

zuluk picture zuluk · Jul 12, 2013 · Viewed 10.9k times · Source

I have a problem while migrating my VBA code from Office2003 to Office2010. I would like to copy the text of a cell (Excel) to Powerpoint. Office2003 generated a new textbox and the style of the text was the same as in Excel. Now my code fails with Office2010 and I get the following message:

runtime error -2147188160 (80048240) Shapes.PasteSpecial : Invalid request. Clipboard is empty or contains data which may not be pasted here.

The clipboard is definitly not empty.

The code is the following:

Set mySlides = obj_pp.ActivePresentation.Slides
mySlides(Slidenum).Shapes.PasteSpecial DataType:=ppPasteRTF

I have already tried other DataTypes and the Paste-function. Nothing helped. The text, I copy from Excel, is also formatted as text in Excel. Nothing special. The slide is added as an empty one. After adding the slide a picture is pasted (DataType:=ppPasteEnhancedMetafile). And after that the text should be pasted.

Could someone please help me to get this code work? Thanks in advance. Please let me know if more code is needed.

Edits: Binding of the ppt:

Dim Datei As String

Pfad_Server = "..."
Pfad_Verzeichnis = "..."
Dateiname = "....pptx"
Datei = Pfad_Server & Pfad_Verzeichnis & "\" & Dateiname
Set obj_pp = (GetObject(, "Powerpoint.Application"))
obj_pp.Visible = True
IsOpen = False

Before running the macro I always open the ppt. This works fine.

Adding slide and pasting range as picture (works fine):

Range(Cells(start_var, 1), Cells(bereich_ende, 13)).Select
Selection.CopyPicture xlScreen, xlPicture
...
Set mySlides = obj_pp.ActivePresentation.Slides

mySlides.Add Index:=mySlides.Count + 1, Layout:=12 'ppLayoutBlank
mySlides(Slidenum).Shapes.PasteSpecial DataType:=ppPasteEnhancedMetafile

Answer

Kazimierz Jawor picture Kazimierz Jawor · Jul 12, 2013

In my opinion you need to change method which copies your range. Use this lines instead your .CopyPicture line:

Selection.Copy

and it will work with pasting method:

mySlides(mySlides.Count).Shapes.PasteSpecial DataType:=9

where 9 = ppPasteRTF.