+ Reply to Thread
Results 1 to 4 of 4

macro to copy chart from excel to powerpoint slides

Hybrid View

  1. #1
    Registered User
    Join Date
    01-06-2015
    Location
    Kharagpur
    MS-Off Ver
    2007
    Posts
    2

    macro to copy chart from excel to powerpoint slides

    I used your above given code and i want to use some specific template so also used your comment but this is inserting charts in the end slides of template and need to specific slide and placeholder function syntax is not doing any changes.
    Please suggest chages to fix this.
    Sub PushChartsToPPT()
    'Set reference to 'Microsoft PowerPoint 12.0 Object Library'
    'in the VBE via Tools > References...
    '
    Dim ppt As PowerPoint.Application
    Dim pptPres As PowerPoint.Presentation
    Dim pptSld As PowerPoint.Slide
    Dim pptCL As PowerPoint.CustomLayout
    Dim pptShp As PowerPoint.Shape

    Dim cht As Chart
    Dim ws As Worksheet
    Dim i As Long

    Dim strPptTemplatePath As String

    strPptTemplatePath = "E:\Macro\demo template.pptx"

    'Get the PowerPoint Application object:
    Set ppt = CreateObject("PowerPoint.Application")
    ppt.Visible = msoTrue
    Set pptPres = ppt.Presentations.Open(strPptTemplatePath, untitled:=msoTrue)


    'Get a Custom Layout:
    For Each pptCL In pptPres.SlideMaster.CustomLayouts
    If pptCL.Name = "Title and Content" Then Exit For
    Next pptCL

    'Copy ALL charts in Chart Sheets:
    For Each cht In ActiveWorkbook.Charts
    Set pptSld = pptPres.Slides.AddSlide(pptPres.Slides.Count + 1, pptCL)
    pptSld.Select

    For Each pptShp In pptSld.Shapes.Placeholders
    If pptShp.PlaceholderFormat.Type = ppPlaceholderObject Then Exit For
    Next pptShp
    If pptShp Is Nothing Then Stop

    cht.ChartArea.Copy
    ppt.Activate
    pptShp.Select
    ppt.Windows(1).View.Paste
    Next cht

    'Copy ALL charts embedded in EACH WorkSheet:
    For Each ws In ActiveWorkbook.Worksheets
    For i = 1 To ws.ChartObjects.Count
    Set pptSld = pptPres.Slides.AddSlide(pptPres.Slides.Count + 1, pptCL)
    pptSld.Select

    'Find the right placeholder to paste into:
    For Each pptShp In pptSld.Shapes.Placeholders
    If pptShp.PlaceholderFormat.Type = ppPlaceholderObject Then
    If pptShp.Left = 50 Then Exit For
    End If
    Next pptShp

    For Each pptShp In pptSld.Shapes.Placeholders
    If pptShp.PlaceholderFormat.Type = ppPlaceholderObject Then Exit For
    Next pptShp

    Set cht = ws.ChartObjects(i).Chart
    cht.ChartArea.Copy
    ppt.Activate
    pptShp.Select
    ppt.Windows(1).View.Paste
    Next i
    Next ws
    End Sub
    Thanks

  2. #2
    Registered User
    Join Date
    09-01-2011
    Location
    georgia
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: macro to copy chart from excel to powerpoint slides

    I know this may not be a great answer but I have done this before in C# to automate a PowerPoint and copy Excel charts over to it.

    chart.ChartArea.Copy();
    Powerpoint.Slide slide = ppPres.Slides[slideNum];
    Powerpoint.ShapeRange shapeRange = slide.Shapes.Paste();
    Essentially, you want to paste your Chart object to the Shapes object of the active slide.

    This is an example I found online which may help you with syntax and other commands:
    Sub ChartToPresentation()
    ' Uses Early Binding to the PowerPoint Object Model
    ' Set a VBE reference to Microsoft PowerPoint Object Library
    
    Dim PPApp As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide
    
    ' Make sure a chart is selected
    If ActiveChart Is Nothing Then
        MsgBox "Please select a chart and try again.", vbExclamation, _
            "No Chart Selected"
    Else
        ' Reference existing instance of PowerPoint
        Set PPApp = GetObject(, "Powerpoint.Application")
        ' Reference active presentation
        Set PPPres = PPApp.ActivePresentation
        PPApp.ActiveWindow.ViewType = ppViewSlide
        ' Reference active slide
        Set PPSlide = PPPres.Slides _
            (PPApp.ActiveWindow.Selection.SlideRange.SlideIndex)
        
        ' Copy chart as a picture
        ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, _
            Format:=xlPicture
    
        ' Paste chart
        PPSlide.Shapes.Paste.Select
        
        ' Align pasted chart
        PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
        PPApp.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
    
        ' Clean up
        Set PPSlide = Nothing
        Set PPPres = Nothing
        Set PPApp = Nothing
    End If
    
    End Sub
    <----Don't forget to add reputation if I helped

  3. #3
    Registered User
    Join Date
    01-06-2015
    Location
    Kharagpur
    MS-Off Ver
    2007
    Posts
    2

    Re: macro to copy chart from excel to powerpoint slides

    Hello,
    your second code is copying chart from selected chart in excel to current open slide into presentation but i need to copy various charts to copy in ppt at different slides.
    Hope you understand my problem./
    Thanks

  4. #4
    Registered User
    Join Date
    09-01-2011
    Location
    georgia
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: macro to copy chart from excel to powerpoint slides

    If that is the case, then it would be very helpful to see the source data so that I may have something to test on my end rather than guessing pieces of code that may or may not work for your case.

    If you could attach a sample of your workbook by replying, click "Go Advanced" and click the paperclip attachment icon to directly upload a workbook. If your document contains sensitive data, create a similar one with made up data. Just make sure that the number of graphs and their locations match your source file.

    From there, I can take a look at getting a working macro.

    It would be extremely helpful if you could attach an example of the result you expect as well for your powerpoint presentation. This way, we have the starting point and the end point to compare it to. You'll get a much better response from this forum in the future if you give a very clear idea of the results you would like in addition to the source information.

+ 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. copy specific excel charts to a specific powerpoint slides
    By coolin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-26-2019, 08:52 PM
  2. VBA Copy Range from Excel to Powerpoint slides
    By stepet5618 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-17-2014, 04:32 AM
  3. Create and copy screenshots of Excel 2007 sheets into Powerpoint slides
    By *Flipp* in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-02-2014, 06:01 AM
  4. Looping macro to paste Excel ranges to new Powerpoint slides
    By sammonite in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-06-2012, 05:18 AM
  5. copy cells to powerpoint slides
    By just_some_guy in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-08-2010, 09:34 AM

Tags for this Thread

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