Share via

PowerPoint VBA Chart Data sheet

Anonymous
2014-07-02T14:56:24+00:00

Howdy,

I am trying to loop through all of the charts in a presentation, open the chart sheet, and use the replace function on the contents.

Can someone help me out?

Thanks

Jeff

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2014-07-02T19:06:46+00:00

You probably should set a reference to the Excel 15 Object Library in Tools > References in the vb editor to do this and then

Sub fixEmALL()

Dim ocht As Chart

Dim oshp As Shape

Dim osld As Slide

Dim wb As Excel.Workbook

Dim ws As Excel.Worksheet

Dim strText As String

For Each osld In ActivePresentation.Slides

For Each oshp In osld.Shapes

If oshp.HasChart Then

Set ocht = oshp.Chart

ocht.ChartData.Activate

Set wb = ocht.ChartData.Workbook

Set ws = wb.Worksheets(1)

ws.Cells.Replace What:="old", Replacement:="new"

ocht.Refresh

wb.Close

End If

Next oshp

Next osld

End Sub

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2014-07-02T18:20:05+00:00

    Thanks for the quick reply!  How would I adapt this for all cells?  I cannot seem to do a global replace.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2014-07-02T15:56:24+00:00

    See if this gets you started

    Sub fixEm()

    Dim ocht As Chart

    Dim oshp As Shape

    Dim osld As Slide

    Dim strText As String

    For Each osld In ActivePresentation.Slides

    For Each oshp In osld.Shapes

    If oshp.HasChart Then

    Set ocht = oshp.Chart

    With ocht.ChartData

    .Activate

    strText = .Workbook.worksheets(1).Range("A2").Value

    strText = Replace(strText, "This", "That")

    .Workbook.worksheets(1).Range("A2").Value = strText

    .Workbook.Close

    End With

    End If

    Next oshp

    Nextosld

    End Sub

    Was this answer helpful?

    0 comments No comments