将命名范围图复制到 powerpoint

Copying Named range Graph into powerpoint

我正在编写一个宏启用 powerpoint 演示文稿,我遇到的问题是我试图从 excel sheet 复制一个命名范围(这是一个图表)到power point 演示文稿。

  Dim xlApp As Object
  Dim xlWorkBook As Object
  Dim path As String
  Dim filename As String

  Set xlApp = CreateObject("Excel.Application")
  Set PPApp = GetObject(, "Powerpoint.Application")
  Set PPPres = PPApp.ActivePresentation

  path = "path"
  filename = "name.xlsx"

 Set xlWorkBook = xlApp.Workbooks.Open(path & filename)
 Set positionsheet = xlWorkBook.Sheets("Graphs")


'problem is in the below line
positionsheet.Range("Graph1").CopyPicture Appearance:=xlScreen, Format:=xlPicture 
Set osh = PPPres.Slides(1).Shapes.PasteSpecial(ppPasteEnhancedMetafile)(1)

'adjust size here...

With xlWorkBook
 .Save
 .Close
End With

Set xlApp = Nothing
Set xlWorkBook = Nothing

我收到的错误是

runtime error 1004, object-defined error

我试过:

  positionsheet.Range("Graph1").Select

前面的问题行...没有成功。

用形状替换范围,像这样:

positionsheet.Shapes("Graph1")...

你必须确保你的名字是正确的。它与范围不同,但会显示在与范围名称相同的框中。