图表是通过Microsoft PowerPoint 中的图表功能创建的,我们希望通过使用 PowerPoint 用户表单来控制图表的更新方式。执行例程时,是否有一行代码可以指向Microsoft PowerPoint 中DVPVreport
的图表中命名的工作表?当前代码如下,不考虑DVPVreport
位于 Microsoft PowerPoint 中的图表内。我们尝试执行代码:
Set ws = 'Chart In MicrosoftPowerPoint!'.Worksheets(DVPVreport)
但没有成功。
Private Sub AddDVSetUp_Click()
Dim ws As Worksheet
Set ws = Worksheets("DVPVreport")
ws.Cells(3, 4).Value = Gate2Date.Value
Unload M
ws.Cells(3, 5).Value = Gate3Date.Value
Unload M
End Sub
是的,有可能。试试这个:
Dim sl As Slide
Set sl = ActivePresentation.Slides(1)
Dim xlWB As Object
Dim sh As Shape, ch As Chart
For Each sh In sl.Shapes
If sh.Type = msoChart Then
Set ch = sh.Chart
Set xlWB = ch.ChartData.Workbook
With xlWB.Sheets(1) '/* It has only 1 sheet so this will be fine */
'/* Do the changes you want here */
.Range("B2").Value = 4.2
End With
End If
Next
Set ch = Nothing: Set xlWB = Nothing: Set sl = Nothing '/* clean up */
现在,如果您已经知道对象的索引或名称,您可以简单地:
Dim sl As Slide
Set sl = ActivePresentation.Slides(1)
Dim xlWB As Object
Dim sh As Shape
Set sh = sl.Shapes("Chart 1")
Set xlWB = sh.Chart.ChartData.Workbook
With xlWB.Sheets(1)
.Range("B2").Value = 4.2
End With
重要提示:要非常小心,不要破坏源数据布局。ChartData
当您执行此操作时,它会出于某种原因取消图表与 的关联。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句