+ Reply to Thread
Results 1 to 20 of 20

Copy Excel graphs to Powerpoint

  1. #1
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    822

    Copy Excel graphs to Powerpoint

    Did not seem so hard, but every code I try and find on internet does not seem to work for me.

    It already goed wrong at this :
    Dim PPApp As Object

    Has it something to do with my settings in Excel?

    Furthermore...what would the most simple code be?
    Nothing fancy. I have sheet9, 10, 12, 14, 16, 18 and 19 which have Pivot charts on them.

    I just want the macro go to these sheets and copy the chart to a powerpoint presentation. 1 Chart per slide.
    (maybe in future to pre-defined ppt template with already the text etc filled.
    Thanks.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Excel graphs to Powerpoint

    In the attached, I have an extract from a spreadsheet that does just this. I have a template powerpoint file that has everything else set up except for the charts and the data ranges I want to copy.

    There is some extraneous code that you may want to ignore where I set certain text values. The meat of what you want is in the 'Add Objects section. The spreadsheet has a "map" where I tell this function what page and object to copy, what kind it is (Chart or Range) and where to put it. The Column PPObject isn't used in the code. It's for user comments.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    822

    Re: Copy Excel graphs to Powerpoint

    Thanks for this dflak!
    I will study the code.
    Looks like it will be very helpful for my needs.

  4. #4
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    822

    Re: Copy Excel graphs to Powerpoint

    Ok I am trying to work with your code and start real simple.
    I copy 1 chart in excel, open ppt and want to paste it there like:
    Please Login or Register  to view this content.
    But then i get this error:
    "Object variable or with block variable not set"

    Any suggestion?

  5. #5
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Excel graphs to Powerpoint

    On which line? I'm guessing: Sheet9.Shapes("Chart 1").CopyPicture

    This probably needs to be Sheets("Sheet9").Shapes("Chart 1").CopyPicture

  6. #6
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    822

    Re: Copy Excel graphs to Powerpoint

    Nope. It is the CodeName of the sheet, so that is ok.

    He copies, opens PPT but the line which pastes it does not work.
    If I do a Ctrl+V it will paste it in the PPT.

    So the pasting part is not working.

  7. #7
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Excel graphs to Powerpoint

    Try

    Set sld = ObjPPT.Slides(1)

    instead of
    Set sld = ppt.Slides(1)

    Also I recommend putting Option Explicit at the very beginning of every module of code you ever write. Option Explicit forces you to declare your variables and identifies when a variable (usually a misspelling) is not defined.

    With the module open, go to Tools -> Options and click on the box "Require Variable Declaration." This will put Option Explicit automatically on every new module.

    I also recommend checking off Auto Syntax Check. Quite often I am typing a command and realize that I want to copy and paste from another part of the code. When I leave the line to do this, I get a dialog box that tells me the line has an error. By clicking off this box, this annoyance doesn't happen. The line is still highlighted in red if there is a syntax error.
    Attached Images Attached Images

  8. #8
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    822

    Re: Copy Excel graphs to Powerpoint

    Thanks for this options tweak.

    However the code change did not make it work.
    I am now getting the "Object doesn't support this property or method" error on that line.

  9. #9
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Excel graphs to Powerpoint

    Could you attach the file and the powerpoint too. Let me see what's happening first hand.

  10. #10
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    822

    Re: Copy Excel graphs to Powerpoint

    Am not sure what good that would do.
    The PPT is really a blank fresh ppt which I gave a name.
    So you could just use any other new ppt you open and give a name.
    And the graphic is just a pivot graph on a sheet (and that part works).

    But if you think it would be helpful to attache these 2 I could make an example workbook.
    (cannot attache the whole file, but the excel file is not the problem I think)

  11. #11
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Excel graphs to Powerpoint

    I'll take a look at this. I have some real life work to do at the moment, so it may be a while.

  12. #12
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Excel graphs to Powerpoint

    I made a blank PowerPoint slide with a blank second page (PPT.pptx). The issue was between objPPT, the application and ppt, the active presentation within the application. I had to go back to my code, it's been a while and I've forgotten a couple of things.

    This line: Set objPPT = CreateObject("Powerpoint.application")
    Launches the PowerPoint application.

    This line: objPPT.Presentations.Open MyPath & "\" & PPTFile
    opens up the specific file

    This line: Set ppt = objPPT.activepresentation
    makes a shortcut called ppt so we don't have to type objPPT.activepresentation all the time.

    Please Login or Register  to view this content.
    Th

  13. #13
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: Copy Excel graphs to Powerpoint

    Hi there,

    I have a code and i want to put it into a For..Loop. or into a Do statement.

    Basicaly I want to copy each chart to a ppt sheet. If I have 10 numbers of chart from 10 sheets I want to save them into 10 slides on a given PPT

    Please Login or Register  to view this content.

    Thank you in advance,
    I

  14. #14
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Excel graphs to Powerpoint

    Maybe the attached will help you. It's a "subset" of a project I use to copy ranges and shapes to PowerPoint and position them on the page.

    Excel Page is the name of the Excel Sheet that contains what you want to copy.
    Excel Object is the name of the shape or the range you want to copy.
    Excel Type is Chart for a chart or Range for a range
    PP Page is the PowerPoint page on which you want to put the object.
    PPObject isn't used by the code. It's just comments for the human user.
    Top, Left, Height and Width are the measurements, in inches, to position and size what gets pasted.

    The module has some code to replace text on the title page and to replace footer dates. You can ignore this part of the code. What you want starts with "Add Objects."
    Attached Files Attached Files

  15. #15
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: Copy Excel graphs to Powerpoint

    Thank you Dflak for your prompt response!
    I will study your code and will get back to you if I have a question.

    Have a great day,
    Ionut

  16. #16
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: Copy Excel graphs to Powerpoint

    Hi Dflak,
    I studied your code.
    So you are suggesting in creating first a matrix that will have all the info for the powerpoint. and then based on that Range Name you can take all the variables in order to put them into the PP.
    Am I right?

    If yes, do you have the code that you used on order to extract all the relevant info like chart Name that can be added into an order as per the sheet number?


    Thank you,
    Ionut

  17. #17
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Excel graphs to Powerpoint

    I made the code data-driven so I could change the data and not change the code. So yes, if you have a number of charts or ranges to put in the powerpoint presentation, I do recommend you build a table like I did.

    As far as naming the charts, I right clicked on them and named them manually. I use the same charts each time.

  18. #18
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: Copy Excel graphs to Powerpoint

    Thank you!

  19. #19
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: Copy Excel graphs to Powerpoint

    Hi Dflak,

    How can I add multiple textboxes so they don;t overwrite. The code I have overwrite the first textbox.
    What can i do so they can show properly in ptt?

    Please Login or Register  to view this content.
    Thank you!

    Ionut

  20. #20
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy Excel graphs to Powerpoint

    I'd have to do some experimenting with it. I would think that the last text box created would be the active text box. Somehow
    Please Login or Register  to view this content.
    is getting confused as to which textbox is active. I don't know if there is a way you can name the text box or index it.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] How to copy and paste 4 excel graphs into a single PowerPoint slide evenly?
    By Mirisage in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 03-07-2015, 12:47 AM
  2. Copy Excel Graphs to Powerpoint As Picture
    By Ajay_tippu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-02-2014, 02:15 PM
  3. [SOLVED] Auto generate graphs in excel and copy them to powerpoint
    By aashr in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-27-2013, 12:49 PM
  4. Copy excel charts/graphs to Powerpoint with/without copying worksheet
    By ThomasCarter in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 11-12-2012, 09:05 AM
  5. Copy Graphs and other Data into PowerPoint a slide at a time.
    By kpierce in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2011, 02:11 AM
  6. Copy graphs to a powerpoint
    By joe12613 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-28-2009, 07:21 AM
  7. [SOLVED] Loop through combo and copy graphs to Powerpoint
    By Martin Los in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-04-2005, 08:05 AM

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