我正在使用Belisarius的这个特殊代码:
Sub a()
Dim oSl As PowerPoint.Slide
Dim oSh As PowerPoint.Shape
Set oSl = ActivePresentation.Slides(1)
Set oSh = oSl.Shapes(1)
With oSh.OLEFormat.Object.WorkSheets(1)
.Range("A1").Value = .Range("A1").Value + 1
.Range("A2").Value = .Range("A2").Value - 1
End With
Set oSl = Nothing
Set oSh = Nothing
End Sub
我使用PowerPoint 2010中的插入菜单嵌入了一个折线图(可以在excel中更改值)。我收到一条错误,说明了OLEFormat(未知成员):无效请求。我知道这对那里的某个人有用,但显然我插入的不是一个对象。为什么我收到此错误?
答案 0 :(得分:1)
访问基础Excel工作表有点棘手 - 尝试这种方法
Sub Test()
Dim myChart As Chart
Dim myChartData As ChartData
Dim myWorkBook As Object
Dim myWorkSheet As Object
Set myChart = ActivePresentation.Slides(1).Shapes(1).Chart
Set myChartData = myChart.ChartData
myChartData.Activate
Set myWorkBook = myChartData.Workbook
Set myWorkSheet = myWorkBook.Worksheets(1)
With myWorkSheet
.Range("A1").Value = .Range("A1").Value + 1
.Range("A2").Value = .Range("A2").Value - 1
End With
myWorkBook.Close
Set myWorkBook = Nothing
End Sub