VBA Office2010 Shapes.PasteSpecial 失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17613119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA Office2010 Shapes.PasteSpecial fails
提问by zuluk
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:
将 VBA 代码从 Office2003 迁移到 Office2010 时遇到问题。我想将单元格 (Excel) 的文本复制到 Powerpoint。Office2003 生成了一个新的文本框,文本的样式与 Excel 中的相同。现在我的代码在 Office2010 上失败了,我收到以下消息:
runtime error -2147188160 (80048240) Shapes.PasteSpecial : Invalid request. Clipboard is empty or contains data which may not be pasted here.
运行时错误 -2147188160 (80048240) Shapes.PasteSpecial:请求无效。剪贴板为空或包含可能无法粘贴到此处的数据。
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.
我已经尝试过其他数据类型和粘贴功能。没有任何帮助。我从 Excel 复制的文本也在 Excel 中格式化为文本。没什么特别的。幻灯片被添加为空的。添加幻灯片后,将粘贴图片(DataType:=ppPasteEnhancedMetafile)。之后应该粘贴文本。
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:
编辑: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.
在运行宏之前,我总是打开ppt。这工作正常。
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
采纳答案by Kazimierz Jawor
In my opinion you need to change method which copies your range. Use this lines instead your .CopyPicture
line:
在我看来,您需要更改复制范围的方法。使用此行代替您的.CopyPicture
行:
Selection.Copy
and it will work with pasting method:
它将使用粘贴方法:
mySlides(mySlides.Count).Shapes.PasteSpecial DataType:=9
where 9 = ppPasteRTF
.
哪里9 = ppPasteRTF
。