Consulting

Results 1 to 6 of 6

Thread: Accessing PowerPoint Chart with VBA

  1. #1

    Question Accessing PowerPoint Chart with VBA

    I am wondering how to access a PowerPoint chart with VBA. I would like to change the y-axis parameters for my chart but can't seem to figure out how to get down to that level. I found the following example code in another forum but receive an error on the With Statement line of code. Any thoughts?

    Sub Test()
    
    Dim oSl As PowerPoint.Slide
    Dim oSh As PowerPoint.Shape
    
    
    Set oSl = ActivePresentation.Slides(1)
    Set oSh = oSl.Shapes(1)
    With oSh.OLEFormat.Object.WorkSheets(1)
        .Range("A1").Value = .Range("A1").Value + 1
        .Range("A2").Value = .Range("A2").Value - 1
    End With
    
    
    Set oSl = Nothing
    Set oSh = Nothing
    
    
    End Sub
    Chris Macro

    The Spreadsheet Guru
    Using Office 2007 (Windows 7) & Office 2013 (Windows 8)
    Twitter | Facebook| Google+

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    That looks like code for the old style MSGraph (from 2003)

    Chart vba is pretty broken in 2007 but in theory charts are treated much the same as in Excel.

    Sub charter()
    Dim ocht As Chart
    Set ocht = ActivePresentation.Slides(1).Shapes(3).Chart
    With ocht.ChartData.Workbook.worksheets(1)
    .Range("B2") = 50
    .Range("C2") = 12
    End With
    End Sub
    Be aware though this will error if the data sheet is not still open. Leave it minimised and see if that works (it does in 2010)
    Last edited by John Wilson; 10-06-2014 at 10:05 AM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    I am getting a Method not Found Error in Excel 2007. I even added the Excel Object Library and still no luck...may it is really, really broken in 2007!

    Set ocht = ActivePresentation.Slides(1).Shapes(3).Chart
    Chris Macro

    The Spreadsheet Guru
    Using Office 2007 (Windows 7) & Office 2013 (Windows 8)
    Twitter | Facebook| Google+

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    I just fired up a 2007 PC. Yep it is broken in 2007 - there's no chart object as there is in 2010 / 13
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    Ok, well I will have to wait until I get home then to see if I can figure it out on Excel 2013. Will keep you posted on my progress.
    Chris Macro

    The Spreadsheet Guru
    Using Office 2007 (Windows 7) & Office 2013 (Windows 8)
    Twitter | Facebook| Google+

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Chris

    I found out the 2007 box had not been updated. Installed SP 3 and it is easier (not good but easier)

    There is a shp.Chart.ChartData object but you must activate before it can be changed (have it minimised).
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •