将命名范围图表复制到powerpoint中

时间:2018-01-19 09:16:59

标签: vba powerpoint named-ranges

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

  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

我收到的错误是

  

运行时错误1004,对象定义错误

我试过了:

  positionsheet.Range("Graph1").Select

在问题界线前......没有成功。

1 个答案:

答案 0 :(得分:1)

用形状替换范围,如下所示:

positionsheet.Shapes("Graph1")...

您必须确保自己拥有正确的名称。它与范围不同,但它将与范围名称显示在同一个框中。