所以这个错误似乎出现了很多原因,但其他解决方案似乎都没有解决我面临的问题。我有一个从excel运行的脚本将表复制到powerpoint幻灯片,但我不断收到“Shapes(未知成员):无效请求”。
不的原因是:
代码:
请记住,我省略了路径和不相关的代码段......
Dim PPT As PowerPoint.Application
Set PPT = New PowerPoint.Application
PPT.Visible = True
PPT.Presentations.Open Filename:= "#######################"
Set curWS = Worksheets("###############")
curWS.Select
Set pt = curWS.PivotTables(1)
Set ptRg = pt.TableRange1
Set ptRg = Range(curWS.Cells(ptRg.Row - 1, ptRg.Column), _
curWS.Cells(ptRg.Row + ptRg.Rows.Count - 1, ptRg.Columns.Count + ptRg.Column - 1))
ptRg.Select
Selection.Copy
DoEvents
PPT.ActivePresentation.Application.ActiveWindow.Panes(2).Activate
PPT.ActivePresentation.Application.ActivePresentation.Slides(2).Select
PPT.ActivePresentation.Application.ActivePresentation.Slides(2).Shapes.PasteSpecial ppPastePNG, msoFalse
答案 0 :(得分:0)
尝试将 ppPastePNG 更改为 ppPasteEnhancedMetafile 。
e.g。
PPT.ActivePresentation.Slides(2).Shapes.PasteSpecial ppPasteEnhancedMetafile, msoFalse
答案 1 :(得分:0)
使用下面的代码修改代码中的最后几行(使用 myShape 对象,以后可以让您轻松修改图片参数)
Dim myShape As Object
PPT.ActivePresentation.Application.ActiveWindow.Panes(2).Activate
ptRg.Select
Selection.Copy
Set myShape = PPT.ActivePresentation.Slides(2).Shapes.PasteSpecial(ppPastePNG, msoFalse)
答案 2 :(得分:0)
显然它有时不能正确复制,然后进入粘贴部分,什么也没有...
我设法通过在选择和复制命令之前放置Application.CutCopyMode = False来解决此问题
示例:
Application.CutCopyMode = False
'Selecting and copying
Range("ExportTable").Copy
' Pasting and giving format
With PPSlide.Shapes.PasteSpecial(DataType:=2)
.Align msoAlignLefts, msoTrue
.Align msoAlignCenters, True
.Align msoAlignMiddles, True
.IncrementTop (dist_top)
.Top = 70
.Left = 15
.LockAspectRatio = msoFalse
.Height = 90
.Width = 690
End With