0

我在 excel 中有一个带有旋转按钮的图表,该按钮可以在按下时更改值以更改图表。我可以使用 insert -> object 将它们导入到 powerpoint 中,但这不会使旋转按钮可用。

我正在尝试获取它,因此在显示演示文稿时,我可以单击旋转按钮,图表将相应更改,就像它在 excel 中一样。这可能吗?

4

2 回答 2

1

旋转按钮连接到宏,这就是导致图表在 Excel 中发生变化的原因。

您可以从 Excel 复制代码并将其放在 Powerpoint 文件中的标准模块中。

您可能需要进行一些调整 - 或多或少,取决于原始宏的编写情况(例如,如果它充满了ActiveSheet.ThisActiveChart.That那么它需要比使用ChartChartObject变量来表示更多的调整图表。

以下是与 powerpoint 图表交互的示例:

Sub TEST()
Dim sld As slide
Dim cht As Chart
Dim srs As Series

Set sld = ActivePresentation.Slides(1) 'Modify to be the correct slide #'

'You can hardcode the shape by index if you know it, otherwise'
' this method will apply to the FIRST chart object found on the slide'
For i = 1 To sld.Shapes.count
    If sld.Shapes(i).Type = msoChart Then
        Set cht = sld.Shapes(i).Chart
        Exit For
    End If
Next

'use a variable to interact with the Series:'
Set srs = cht.SeriesCollection(1) '<Modify as needed.'

'specify a particular formula for the series:'
'your macro likely changes the chart's source data/formula information'
' so something like this:'    
srs.Formula = "=SERIES(Sheet1!$B$1,Sheet1!$A$2:$A$5,Sheet1!$B$2:$B$5,1)"

'Or you can display the series formula:'
MsgBox srs.Formula

'Or you can toggle the series axis group:'
With srs
If Not .AxisGroup = xlSecondary Then
    .AxisGroup = xlSecondary
Else
    .AxisGroup = xlPrimary
End If


'etc.'
'Basically anything you can do to an Excel chart in VBA, you can do in PPT.'

End With

End Sub
于 2013-04-12T19:02:22.177 回答
0

当您将任何内容从 Excel 复制/粘贴到 PowerPoint 时,您将获得一个 OLE 对象。PowerPoint 中显示的是您从 Excel 复制的任何内容的 Windows 图元文件图片。您必须激活 Excel 内容(在 PPT 的正常视图中双击它,或为其提供适当的操作设置以使其在幻灯片放映期间激活)。然后微调器也应该在启动的 Excel 实例中工作。

或者您可以在 PPT 中创建另一个微调器并让它运行代码来修改图表(使用 David 的示例代码作为基础)。

于 2013-04-12T22:24:54.923 回答