【问题标题】:How to adapt excel VBA code to PPT VBA?如何将excel VBA代码适配到PPT VBA?
【发布时间】:2017-06-26 19:02:27
【问题描述】:

我想做的是制作 VBA 代码,它将在图表上隐藏和显示各个系列。我知道如何在 Excel 中编写 VBA 代码,但不知道如何在 PPT VBA 中重写相同的代码。

我在 Excel VBA 中有这段代码:

Sub FirstSer()
Dim cht As Chart
Dim ser As Series

'Retrieve our chart and seriescollection objects'
Set cht = Worksheets("Sheet1").ChartObjects("Chart 1").Chart
Set ser = cht.SeriesCollection(1)

'Set the first series line to be hidden'

With ser.Format.Line
    If .Visible = msoTrue Then
        .Visible = msoFalse
        ser.Name = vbNullString
    Else
        .Visible = msoTrue
        ser.Name = "First"
    End If
End With
End Sub

如何在 PowerPoint VBA 中编写相同的代码? 我试图在类似的帖子中找到解决方案,但是每个帖子都考虑了特定的代码,因为我是 VBA 新手,所以我很难适应我的代码。

【问题讨论】:

    标签: vba excel powerpoint


    【解决方案1】:

    替换Excel对图表的具体引用:

    Set cht = Worksheets("Sheet1").ChartObjects("Chart 1").Chart

    Powerpoint 演示文稿中使用对正确对象的引用,如下所示:

    Set cht = ActivePresentation.Slides(1).Shapes(1).Chart

    您的其余代码可以保持原样。

    附带说明: VBA 就是 VBA - PowerPoint VBA 和 Excel VBA 之间没有区别。 当然,在 Excel 中,您会得到一些 Excel 特定的对象,但在一个应用程序或另一个应用程序中使用 VBA 并没有真正的区别。例如,您可以轻松地使用它从 Excel 文件中生成完整的演示文稿。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多