+ Reply to Thread
Results 1 to 3 of 3

Copy Named charts in Excel to specific slide in Powerpoint

Hybrid View

  1. #1
    Registered User
    Join Date
    06-12-2012
    Location
    columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    7

    Copy Named charts in Excel to specific slide in Powerpoint

    Hi, I have a workbook with multiple charts and I am trying to create a macro which will take a named chart and paste it as a picture into a specific slide in PowerPoint. The only code I have been able to find (http://peltiertech.com/Excel/XL_PPT.html) is code that uses the active chart, and the active slide in PowerPoint to decide what is copied and pasted. Is someone smarter than I able to tweak the code below so I can call on a chart by name and then paste it to a specific slide? Any help is greatly appreciated!!


    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

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Copy Named charts in Excel to specific slide in Powerpoint

    Hi

    Can you help us out by creating a couple of example files. A spreadsheet with say 3 graphs, suitably named. A powerpoint with say 4 slides, and have the graphs going to slides 1,2 and 4 (just to be sure that they really are going to the nominated slides).

    rylo

  3. #3
    Registered User
    Join Date
    06-12-2012
    Location
    columbus, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Copy Named charts in Excel to specific slide in Powerpoint

    Hi, someone helped me with the code, here it is:

    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
        
            ' Reference existing instance of PowerPoint
            Set PPApp = GetObject(, "Powerpoint.Application")
            ' Reference active presentation
            Set PPPres = PPApp.ActivePresentation
            PPApp.ActiveWindow.ViewType = ppViewSlide
            
    'Copy "Chart 1" on "Sheet1" to Slide # 2
            ' Copy "Chart 1" on "Sheet1" as a picture
            ActiveWorkbook.Sheets("Sheet1").ChartObjects("Chart 1").CopyPicture
            ' Paste chart  to Slide # 2
            With PPPres.Slides(2).Shapes.Paste
                ' Align pasted chart
                .Align msoAlignCenters, True
                .Align msoAlignMiddles, True
            End With
            
    'Copy "Chart 1" to from "Sheet3" to Slide # 4
            ' Copy "Chart 1" on "Sheet3" as a picture
            ActiveWorkbook.Sheets("Sheet3").ChartObjects("Chart 1").CopyPicture
            ' Paste chart  to Slide # 4
            With PPPres.Slides(4).Shapes.Paste
                ' Align pasted chart
                .Align msoAlignCenters, True
                .Align msoAlignMiddles, True
            End With
            
            ' Clean up
            Set PPSlide = Nothing
            Set PPPres = Nothing
            Set PPApp = Nothing
            
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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