在 PowerPoint 2010 中以静默方式编辑嵌入的 Excel 数据

发布于 2024-11-17 08:38:33 字数 704 浏览 1 评论 0原文

我正在尝试在 PowerPoint 2010 中静默编辑嵌入的 Excel 数据。不幸的是,当您使用:

gChartData.Activate

它会在演示文稿上打开 Excel 文档。有没有办法在不打开Excel的情况下激活ChartData?

完整代码:

Private Sub CommandButton1_Click()

Dim myChart As Chart
Dim gChartData As ChartData
Dim gWorkBook As Excel.Workbook
Dim gWorkSheet As Excel.Worksheet

Set myChart = ActivePresentation.Slides(1).Shapes(1).Chart
Set gChartData = myChart.ChartData

gChartData.Activate

Set gWorkBook = gChartData.Workbook

Set gWorkSheet = gWorkBook.Worksheets(1)

gWorkSheet.Range("B2").Value = 1

Set gWorkSheet = Nothing
Set gWorkBook = Nothing
Set gChartData = Nothing
Set myChart = Nothing


End Sub

提前致谢。

I am trying to edit embedded excel data silently in PowerPoint 2010. Unfortunately when you use:

gChartData.Activate

It opens the Excel document over the presentation. Is there a way to activate the ChartData without opening Excel?

Full Code:

Private Sub CommandButton1_Click()

Dim myChart As Chart
Dim gChartData As ChartData
Dim gWorkBook As Excel.Workbook
Dim gWorkSheet As Excel.Worksheet

Set myChart = ActivePresentation.Slides(1).Shapes(1).Chart
Set gChartData = myChart.ChartData

gChartData.Activate

Set gWorkBook = gChartData.Workbook

Set gWorkSheet = gWorkBook.Worksheets(1)

gWorkSheet.Range("B2").Value = 1

Set gWorkSheet = Nothing
Set gWorkBook = Nothing
Set gChartData = Nothing
Set myChart = Nothing


End Sub

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一杯敬自由 2024-11-24 08:38:33

Steven,

虽然需要 Activate 行才能访问底层工作簿,但在代码中添加一个简单的 gWorkBook.Close (在将其设置为 Nothing 之前)将再次关闭 Excel,而不是而不是像当前代码那样将其保留在顶部。

Private Sub CommandButton1_Click()

    Dim myChart As Chart
    Dim myChartData As ChartData
    Dim gWorkBook As Excel.Workbook
    Dim gWorkSheet As Excel.Worksheet

    Set myChart = ActivePresentation.Slides(1).Shapes(1).Chart
    Set myChartData = myChart.ChartData
    myChartData.Activate

    Set gWorkBook = myChart.ChartData.Workbook
    Set gWorkSheet = gWorkBook.Worksheets(1)
    gWorkSheet.Range("B2").Value = 1

    gWorkBook.Close
    Set gWorkSheet = Nothing
    Set gWorkBook = Nothing
    Set gChartData = Nothing
    Set myChart = Nothing
End Sub

Steven,

While the Activate line is necessary to get access to the underlying Workbook adding a simple gWorkBook.Close to your code (before setting it to Nothing) will close Excel again rather than leave it on top as your current code does.

Private Sub CommandButton1_Click()

    Dim myChart As Chart
    Dim myChartData As ChartData
    Dim gWorkBook As Excel.Workbook
    Dim gWorkSheet As Excel.Worksheet

    Set myChart = ActivePresentation.Slides(1).Shapes(1).Chart
    Set myChartData = myChart.ChartData
    myChartData.Activate

    Set gWorkBook = myChart.ChartData.Workbook
    Set gWorkSheet = gWorkBook.Worksheets(1)
    gWorkSheet.Range("B2").Value = 1

    gWorkBook.Close
    Set gWorkSheet = Nothing
    Set gWorkBook = Nothing
    Set gChartData = Nothing
    Set myChart = Nothing
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文