Link to home
Start Free TrialLog in
Avatar of APD Toronto
APD TorontoFlag for Canada

asked on

Accessing a Embedded Sheet

Hi Experts,

I received a PowerPoint with a chart object.  If I right-click the chart, then Edit Data, I see a Excel sheet.

Is there a way to directly accessing this sheet (not by right-clicking the chart)?

Thanks!
Avatar of Rgonzo1971
Rgonzo1971

Hi,

pls try something like this

Sub macro()
With ActivePresentation.Slides(1).Shapes(1).Chart.ChartData
    .Activate ' Activate Excel
    Set myRange = .Workbook.Sheets(1).UsedRange
    MsgBox myRange.Address
    .Workbook.Close
End With
End Sub

Open in new window

Regards
Avatar of APD Toronto

ASKER

Can you access it physically, in design mode?
Could you be more precise?
Sorry I was away, but from your VBA code above how can I find our what shape number is my chart, because I have a lot of objects on my slide?

I inserted your code, but it does not work and I think the shape number is my issue.
ASKER CERTIFIED SOLUTION
Avatar of Rgonzo1971
Rgonzo1971

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How can I name my shape?
it is named automatically if not done with vba

have you tried my second code?
I have been doing VBA for 15+ Years, but this  is my first time within PowerPoint and I find it very awkward.  For example, if there is an error, simply nothing happens (even with Option Explicit on) and there is no error reported, so I end up placing message boxes to isolate problematic code blocks.

That said, I broke up your code as follows

'.....
'...
    ActivePresentation.Slides(intNextSlide).Shapes("txtGrowth").OLEFormat.Object.Text = "--"
    ActivePresentation.Slides(intNextSlide).Shapes("txtCirius").OLEFormat.Object.Text = "--"

MsgBox "vals reset"

    'reset chart values
    Dim objChart As Chart
    Dim shp As Shape
    
    'getChart intSlide:=intNextSlide, objChart:=objChart
    For Each shp In ActivePresentation.Slides(intNextSlide).Shapes
    
        If shp.HasChart Then
            
            Set objChart = shp
            Exit For
        
        End If
    
    Next

MsgBox "assigned chart"

End Sub

Open in new window


With this in place, I'm getting "vals reset", but not "assigned chart".  What's wrong?
Could you send a dummy?
Got it with a few tweaks

Option Explicit

Sub reset()

    Dim intCount As Integer
    intCount = ActivePresentation.Slides(1).Shapes("txtCount").OLEFormat.Object.Text
    ActivePresentation.Slides(1).Shapes("txtCount").OLEFormat.Object.Text = intCount + 1
    
    'Get chart object's name
    Dim strChartName As String
    strChartName = getChartName(1)
    
    With ActivePresentation.Slides(1).Shapes(strChartName).Chart.ChartData
    
        .Activate ' Activate Excel
        .Workbook.Application.Visible = False
        .Workbook.Sheets(1).Range("B3").Value = intCount
        
        'Set myRange = .Workbook.Sheets(1).UsedRange
        'MsgBox myRange.Address
        .Workbook.Close
        
    End With

    
End Sub

Function getChartName(intSlide As Integer) As String
   
    Dim shp As Shape
    
    For Each shp In ActivePresentation.Slides(1).Shapes
    
        If shp.HasChart Then
            getChartName = shp.Name
            Exit For
        
        End If
    
    Next

    
End Function

Open in new window


Thanks