在 PowerPoint 2010 中以静默方式编辑嵌入的 Excel 数据
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Steven,
虽然需要
Activate
行才能访问底层工作簿,但在代码中添加一个简单的gWorkBook.Close
(在将其设置为 Nothing 之前)将再次关闭 Excel,而不是而不是像当前代码那样将其保留在顶部。Steven,
While the
Activate
line is necessary to get access to the underlying Workbook adding a simplegWorkBook.Close
to your code (before setting it to Nothing) will close Excel again rather than leave it on top as your current code does.