gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 02:15:56 32 4
gpt4 key购买 nike

我正在尝试在 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

提前致谢。

最佳答案

史蒂文,

虽然需要 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

关于excel - 在 PowerPoint 2010 中以静默方式编辑嵌入的 Excel 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6456236/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com