+ Reply to Thread
Results 1 to 2 of 2

VBA Code to select charts based on VBA code

Hybrid View

  1. #1
    Registered User
    Join Date
    05-27-2011
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    1

    Post VBA Code to select charts based on VBA code

    Hi All,

    I would like to manipulate the Peltier VBA 'Excel to Powerpoint' code (find below) to copy across multiple charts automatically (without having to select them individually by hand). The charts I need to copy across are based on an IF statement which shows if the category is spending more than the average and then display an "X" next to the row.

    I have tried the original Peltier code and it works brilliantly but I just need help with the selection code. Is this possible?

    Thanks in advance.

    Will



    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 Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: VBA Code to select charts based on VBA code

    You need to post an example to clarify the IF condition and how it can be used to identify which chart to use.
    Cheers
    Andy
    www.andypope.info

+ 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