VBA Office2010 Shapes.PasteSpecial失败 [英] VBA Office2010 Shapes.PasteSpecial fails

查看:729
本文介绍了VBA Office2010 Shapes.PasteSpecial失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将VBA代码从Office2003迁移到Office2010时遇到问题.我想将单元格(Excel)的文本复制到Powerpoint. Office2003生成了一个新的文本框,其文本样式与Excel中相同.现在,我的代码在Office2010中失败,并且出现以下消息:

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:

运行时错误-2147188160(80048240) Shapes.PasteSpecial:无效的请求.剪贴板为空或包含了可能无法粘贴到此处的数据.

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

剪贴板绝对不是空的.

代码如下:

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

我已经尝试了其他数据类型和粘贴功能.没有任何帮助.我从Excel复制的文本在Excel中也被格式化为文本.没什么特别的.幻灯片被添加为一个空的幻灯片.添加幻灯片后,将粘贴图片(DataType:= ppPasteEnhancedMetafile).然后粘贴文本.

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.

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

在运行宏之前,我总是打开ppt.效果很好.

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

推荐答案

我认为您需要更改复制范围的方法.使用此行代替您的.CopyPicture行:

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

其中9 = ppPasteRTF.

这篇关于VBA Office2010 Shapes.PasteSpecial失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆