VBA Office2010 Shapes.PasteSpecial fails

蹲街弑〆低调 提交于 2020-02-04 04:04:12

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/17613119/vba-office2010-shapes-pastespecial-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!