[Power Point][Excel] Programming data labels for a ppt existing Chart
Hi all,
I am new to this forum and new to VBA, and I have to update a way-to-old macro into 2010. And I am honestly stuck, so I would appreciate your wisdom.
Objective: Add data labels to existing xy (scatter) and bubble charts in power point 2010 presentations. This data labels show specific values taken form specific cells in the datasheet of the chart (for example if data is in columns, after a blank column, or if in rows, after a blank row). These values can be anything, but they are mostly text.
Problem: The new object Chart, and the fact that it is linked to Excel.
So far I managed to declare some variables and select the Chart I have to work with, but from here I do not seem to be able to understand the inner workings of the Chart object. As a linked object to Excel, do I have to program the actions as if I were in Excel? How do I work with the Worksheet of the ChartData object?
The code I worked so far:
Code:
Option Explicit
Sub FirstTry()
On Error GoTo Error1_Err
Dim objChart As Chart
Dim objData As ChartData
Set objChart = ActivePresentation.Slides(1).Shapes(1).Chart
CODE NEEDED
The Chart has to be the first shape in the first slide.
How can I make the macro to work on a Chart in any part of the presentation just by selecting it?
Code:
Set objData = objChart.ChartData
If Not objChart Is Nothing Then
objChart.Format.Fill.BackColor.RGB = 4
If objChart.PlotBy = xlRows Then
With objChart
How do I access the data in the datasheet from here on?
SUGGESTED CODE (yet I still need to link it to the main sub)
Code:
If objData.IsLinked = True Then
objData.Activate
‘as one example of something I would like to do with the data on the datasheet
objData.Workbook.Worksheets("sheet1").Range("A1:B2").Select
End if
It doesn't work!, it has to be Excel? (See below)
Code:
End With
End If
objChart.Refresh
End If
Exit Sub
Error1_Err:
MsgBox ("An Error has occurred ") & Err.Description & vbCrLf & Err.Number
End Sub
If the Chart datasheet has to be coded as in Excel, maybe like this:
CODE NEEDED, how to link the following code with the object Chart in ppt?
Code:
Dim LastRow as Integer
Dim TotalYRows as Integer
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
‘Data Label value starts at LastRow+2
TotalYRows = LastRow – 1
‘First row has series names, row 2 to LastRow contains Y values
For i=LastRow+2 To LastRow+2+TotalYRows
‘The rows that contain the data label values of each series
‘CODE NEEDED. Assign each row to the series it belongs, _
create the data labels with the corresponding value and show _
the data label next to the series point in the chart.
Next i)
I would really appreciate any help you might give!
Thank you!