+ Reply to Thread
Results 1 to 2 of 2

Auto generate graphs in excel and copy them to powerpoint

Hybrid View

aashr Auto generate graphs in excel... 03-27-2013, 05:24 AM
aashr Re: Auto generate graphs in... 03-27-2013, 12:49 PM
  1. #1
    Registered User
    Join Date
    03-26-2013
    Location
    Karachi, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    2

    Question Auto generate graphs in excel and copy them to powerpoint

    Hello All,

    I have no experience with VBA coding but have researched on forums and have found solutions to my problem but they are not working when combined. I am listing what I am trying to do below.

    1- I have multiple worksheets in a workbook and I want to auto-generate graphs for them. For that purpose, I used the following:
    ================================================================
    Define Name Col_A1
    =INDIRECT("'"&Shts&"'!A2"):INDEX(INDIRECT("'"&Shts&"'!A2:A65536"),MATCH(2,1/(INDIRECT("'"&Shts&"'!A2:A65536")<>"")))

    Define Name Col_B1
    =INDIRECT("'"&Shts&"'!B2"):INDEX(INDIRECT("'"&Shts&"'!B2:B65536"),MATCH(2,1/(INDIRECT("'"&Shts&"'!B2:B65536")<>"")))

    Define Name Shts
    =MID(CELL("filename"),FIND("]",CELL("filename"))+1,255)

    Insert a blank graph and update datasource as follows:
    Values : ='Filename.xls'!Col_B1
    Category (X) axis Labels: ='Filename.xls'!Col_A1
    ================================================================
    This worked fine and I now have my graphs with the relevant data on the various worksheets.

    2- Now, I need to pick up these graphs and insert them into a powerpoint presentation. The code I found and am using is as follows:
    ================================================================
    Sub Charts_PPT()
    Dim ocht As ChartObject
    Dim ws As Worksheet
    Dim pptApp As Object
    Dim pptPres As Object
    Dim pptSld As Object
    Set pptApp = CreateObject("PowerPoint.Application")
    pptApp.Visible = True
    Set pptPres = pptApp.Presentations.Add(msoTrue)
    For Each ws In ActiveWorkbook.Worksheets
    For Each ocht In ws.ChartObjects
    ocht.Copy
    Set pptSld = pptPres.Slides.Add(pptPres.Slides.Count + 1, 11)
    pptPres.Windows(1).View.GotoSlide (pptSld.SlideIndex)
    pptSld.Shapes.Title.TextFrame.TextRange = ws.Name & " " & ocht.Name
    With pptSld.Shapes.Paste
    .Align 1, True
    .Align 4, True
    End With
    Next ocht
    Next ws
    End Sub
    ================================================================
    This code worked fine when I was manually creating a graph on each separate worksheet but now that I have used the formulae in point 1 to auto generate the graphs in excel, when I run this code I have the same data in the graphs repeating themselves in powerpoint.

    Can anybody please help by letting me know what part of the code in point 2 should I change so that I have the charts from excel moved to powerpoint exactly as they are in the multiple worksheets?

    BTW, I have Office 2010.

    Thank you so much.

    Kind Regards,
    Ali Akbar.

  2. #2
    Registered User
    Join Date
    03-26-2013
    Location
    Karachi, Pakistan
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Auto generate graphs in excel and copy them to powerpoint

    Hello Everyone,

    I figured out the solution myself.. I just had to add a line "ws.Activate" after the line "For Each ws In ActiveWorkbook.Worksheets" and it works perfectly.

    Thank you everybody.

    Kind Regards,
    Ali Akbar.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1