Excel 需要将图片粘贴到Powerpoint中,然后定义其位置而不选择它

Excel 需要将图片粘贴到Powerpoint中,然后定义其位置而不选择它,excel,vba,location,powerpoint,paste,Excel,Vba,Location,Powerpoint,Paste,下面是我的一小段代码,我将Excel中的图表作为增强的图元文件粘贴到Powerpoint中,然后将其移动到预定义的位置: PPApp.ActivePresentation.Slides(SlideNumber).Shapes.PasteSpecial (ppPasteEnhancedMetafile) PPApp.ActiveWindow.Selection.ShapeRange.Top = ChartTop PPApp.ActiveWindow.Selection.ShapeRange.Le

下面是我的一小段代码,我将Excel中的图表作为增强的图元文件粘贴到Powerpoint中,然后将其移动到预定义的位置:

PPApp.ActivePresentation.Slides(SlideNumber).Shapes.PasteSpecial (ppPasteEnhancedMetafile)

PPApp.ActiveWindow.Selection.ShapeRange.Top = ChartTop
PPApp.ActiveWindow.Selection.ShapeRange.Left = ChartLeft
当用户在代码的第一行和第二行之间单击鼠标时,就会出现问题。由于形状不再被选中,上述vba代码将失败


通常这不会是一个问题,但宏作为一个整体运行很长时间,在循环中多次发生这种情况。有没有一种可行的方法来定义粘贴图片的位置而不需要选择形状?

您几乎不需要选择任何东西来使用它

' if you're running the code from within PowerPoint:
Dim oSh as Shape
' or if from Excel:
Dim oSh as Object

' Get a reference to the newly pasted shape
' Don't miss the (1) at the end
Set oSh = PPApp.ActivePresentation.Slides(SlideNumber).Shapes.PasteSpecial (ppPasteEnhancedMetafile)(1)

With oSh
  .Top = ChartTop
  .Left = ChartLeft
End With

谢谢您!很好用!