我想在自定义布局中将指定的excel范围粘贴到powerpoint中的内容占位符。我目前使用这样的代码VBA:将excel范围粘贴到powerpoint占位符而不使用。选择
ranger.Copy
currentPPT.ActiveWindow.View.GotoSlide ppt.slides.Count
activeSlide.shapes("Picture").Select msoTrue
ppt.Windows(1).View.PasteSpecial (ppPasteEnhancedMetafile)
它通常工作,但有时莫名其妙地失败。我在本网站的其他地方看过,here for example,说避免使用.Select方法。而是使用类似于
Dim oSh As Shape
Set oSh = ActivePresentation.Slides(9).Shapes.PasteSpecial(ppPasteEnhancedMetafile)(1)
但是,我无法弄清楚如何使用第二种方法直接复制到内容占位符。那可能吗?
编辑,关于Shai的建议。当前的代码是
For ii = activeSlide.shapes.Count To 1 Step -1
If activeSlide.shapes.Item(ii).Name = "Picture" Then
shapeInd = ii
Exit For
End If
Next ii
Set oSh = activeSlide.shapes.PasteSpecial(2, msoFalse)(shapeInd)
“图片”形状是一个“内容”占位符。另外两个形状是文本框。
看看我的答案和下面的代码,让我知道,如果它是你打算 –