Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit embedded excel data silently, in PowerPoint 2010

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.

like image 387
Steven Avatar asked Jun 23 '11 15:06

Steven


People also ask

How do I update an Excel table in PowerPoint?

To edit a linked Excel worksheet, do one of the following: To edit the data from within Excel, right-click the object on the slide, point to Linked Worksheet Object, and select Edit. To update the data on the slide to match the data in the original Excel file, right-click the object on the slide, and click Update Link.

How do I Link Excel to dynamic data updates in PowerPoint?

1) Create a chart in Excel and copy it. 2) Use Paste Special option and paste the copied chart into PowerPoint with data link. 3) Click on File > Info > select Automatic for Update option > Close. 4) Now save the PowerPoint and Excel files and close them.


1 Answers

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
like image 139
brettdj Avatar answered Oct 08 '22 19:10

brettdj