Reputation: 1514
I have 2 questions.
1. I have VS2010 with Frameowrk 3.5 and need to lift some data and text and update some existing Powerpoint files. What would be the best approach ? I'm new to VSTO but have been using C# for quite a while.
2. I've been testing with the Interop libraries (Microsoft.Office.Interop.PowerPoint) So I need to open a powerpoint and change some text in all slides and charts. Slides and sahapes are no problem but charts seem to be a problem. There doesn't seem to be a charts collection and if (shape.Type == Office.MsoShapeType.msoChart) returns false.
I've done this previously in VBA and used the code below
For Each chtChart In sht.ChartObjects
chtChart.Chart.ChartTitle.Characters.Text = Replace (chtChart.Chart.ChartTitle.Characters.Text, "{month}", strCurrent, VbCompareMethod.vbTextCompare)
Next chtChart
I just really want to do the same.
Am I missing something really obvious ?
Any pointers gratefully received.
Steve
Upvotes: 1
Views: 701
Reputation: 14809
There are several types of charts you might run across in PPT. Ignoring the old MSGraph charts, you might find charts that the user has added using Insert | Chart.
These will be shapes of .Type = 3 (msoChart). Here's an example of how you get at the chart and/or chart data for these:
Sub ShowChartData()
Dim oSh As Shape
Dim oCht As Chart
Dim oData As ChartData
Dim x As Long
Dim y As Long
Dim sTemp As String
Set oSh = ActiveWindow.Selection.ShapeRange(1)
Set oCht = oSh.Chart
oCht.ChartData.Activate
Set oData = oCht.ChartData
For x = 1 To 4
For y = 1 To 4
sTemp = sTemp & oData.Workbook.Worksheets("Sheet1").Cells(x, y) & vbTab
Next ' y/cell
Debug.Print sTemp
sTemp = ""
Next ' x/row
' do this to get rid of visible worksheet
oData.Workbook.Close
Set oData = Nothing
Set oCht = Nothing
End Sub
Charts might also be linked or embedded objects copy/pasted from Excel.
Upvotes: 1