在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
提前致谢。
史蒂芬,
尽管Activate
行对于访问底层Workbook是必要的,但添加一个简单的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
链接地址: http://www.djcxy.com/p/7973.html