+ Reply to Thread
Results 1 to 7 of 7

Loop through Excel sheets and copy range to Powerpoint, Almost there!!

  1. #1
    Registered User
    Join Date
    03-14-2016
    Location
    Baltimore, MD
    MS-Off Ver
    2010
    Posts
    6

    Loop through Excel sheets and copy range to Powerpoint, Almost there!!

    Hi Everyone, I've done as much of this as I can on my own (and with help from people much smarter than I). I'm a VBA Newbie.

    I have an Excel spreadsheet that creates a PowerPoint Presentation. By clicking a button on each sheet, it copies a range or chart to the Presentation (thats currently open) as a picture and adds a title to the slide. This works but...

    What I'm trying to do is get it down to just clicking one button and it loops through each sheet that is not hidden, copies the chart and the title and pastes it to a new Slide in PowerPoint without having to go to each sheet and click a button. Kind of like a "Generate PowerPoint" button.

    I have gotten it to the point where it loops through and titles each page, but it wont copy the ranges/charts and it places them in backwards, 5,4,3,2,1 instead of 1,2,3,4,5. I'm not sure where the problem lies.

    Any help would be great!

    Code is below.

    Please Login or Register  to view this content.
    Thanks,
    John

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Loop through Excel sheets and copy range to Powerpoint, Almost there!!

    I would likely wrap a named range around each of the pieces of data you want to bring over to PPT so you can call them out in order in the VBA.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Registered User
    Join Date
    03-14-2016
    Location
    Baltimore, MD
    MS-Off Ver
    2010
    Posts
    6

    Re: Loop through Excel sheets and copy range to Powerpoint, Almost there!!

    Thanks for your suggestion, but I'm not sure I understand. Could you elaborate a little bit?

    There are currently about 60 sheets in this workbook. They will not all be used each time a presentation is generated. About half will be used at any given time depending on the needs. Right now it looks for sheets that are not hidden and uses the numbered range (which is the same for each page and obviously doesn't work). If I name the ranges, they would have to be a different name on each worksheet. How would I tell it to use the proper named range on the proper sheet? Or am I totally not understanding, Keeping in mind I'm relatively new to VBA, just started to play with it in February.

    Thanks,
    John

  4. #4
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Loop through Excel sheets and copy range to Powerpoint, Almost there!!

    Well the real question is do you WANT the flexibility of looping through ALL sheets, or just the relevant sheets. If you use a named range and explicitly call out the sheet to grab data from you can avoid the problem in which you are having it pull in 5,4,3,2,1.

    I think the last time I did this I created a MASTER Excel file that I linked myself to a MASTER Powerpoint. Once they were linked when I wanted to update and create a PDF I would use VBA to update the raw data in the master and then refresh the powerpoint finally saving the PPT as a new filename after breaking the links. I found that easier than trying to copy and paste values or pictures or whatever from Excel to Powerpoint.

    If I remember correctly I just made a list of sheets and charts to be looped through and then I could manage the VBA by simply updating my table to loop through. It SOUNDS complicated but it allowed me to hand the process off to someone with ZERO vba experience and have them NOT call me every 5 minutes with a change request.

  5. #5
    Registered User
    Join Date
    03-14-2016
    Location
    Baltimore, MD
    MS-Off Ver
    2010
    Posts
    6

    Re: Loop through Excel sheets and copy range to Powerpoint, Almost there!!

    I like the idea of having the list to loop through however my VBA knowledge is limited and I'm not sure how to go about doing that.

    Just like you, there will be people using this spreadsheet and I don't want them calling every 5 minutes either. This spreadsheet will also be used by another office in another state.

  6. #6
    Forum Contributor
    Join Date
    08-02-2012
    Location
    Pune
    MS-Off Ver
    Office 365 (Win 10)
    Posts
    489

    Re: Loop through Excel sheets and copy range to Powerpoint, Almost there!!

    hmm....

    I was using this code for that. But it doesnt go to each tab and copy paste. Just from a single sheet

    PHP Code: 
    Sub CreatePowerPoint()



     
    'Add a reference to the Microsoft PowerPoint Library by:
        '
    1. Go to Tools in the VBA menu
        
    '2. Click on Reference
        '
    3. Scroll down to Microsoft PowerPoint X.0 Object Librarycheck the box, and press Okay
     
        
    'First we declare the variables we will be using
            Dim newPowerPoint As PowerPoint.Application
            Dim activeSlide As PowerPoint.Slide
            Dim cht As Excel.ChartObject
         Dim PPT As PowerPoint.Application
     Set PPT = New PowerPoint.Application
     PPT.Visible = True
     PPT.Presentations.Open Filename:="\\C\Template.pptx" '
    change your ppt path here
         
    'Look for existing instance
            On Error Resume Next
            Set newPowerPoint = GetObject(, "PowerPoint.Application")
            On Error GoTo 0
         
        '
    Let's create a new PowerPoint
            If newPowerPoint Is Nothing Then
                Set newPowerPoint = New PowerPoint.Application
            End If
        '
    Make a presentation in PowerPoint
            
    If newPowerPoint.Presentations.Count 0 Then
                newPowerPoint
    .Presentations.Add
            End 
    If
         
        
    'Show the PowerPoint
            newPowerPoint.Visible = True
        
        '
    Loop through each chart in the Excel worksheet and paste them into the PowerPoint
            
    For Each cht In ActiveSheet.ChartObjects
            
            
    'Add a new slide where we will paste the chart
                newPowerPoint.ActivePresentation.Slides.Add newPowerPoint.ActivePresentation.Slides.Count + 1, ppLayoutText
                newPowerPoint.ActiveWindow.View.GotoSlide newPowerPoint.ActivePresentation.Slides.Count
                Set activeSlide = newPowerPoint.ActivePresentation.Slides(newPowerPoint.ActivePresentation.Slides.Count)
                    
            '
    Copy the chart and paste it into the PowerPoint as a Metafile Picture
                cht
    .Select
                ActiveChart
    .ChartArea.Copy
                activeSlide
    .Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select
        
            
    'Set the title of the slide the same as the title of the chart
                activeSlide.Shapes(1).TextFrame.TextRange.Text = cht.Chart.ChartTitle.Text
                
            '
    Adjust the positioning of the Chart on Powerpoint Slide
                newPowerPoint
    .ActiveWindow.Selection.ShapeRange.Left 15
                newPowerPoint
    .ActiveWindow.Selection.ShapeRange.Top 80
            
                activeSlide
    .Shapes(2).Width 200
                activeSlide
    .Shapes(2).Left 505
                
            Next
         
        AppActivate 
    ("Microsoft PowerPoint")
        
    Set activeSlide Nothing
        Set newPowerPoint 
    Nothing
         
    End Sub 
    Please make the Post as solved, when you get your answer & Click * if you like my suggestion

  7. #7
    Registered User
    Join Date
    03-14-2016
    Location
    Baltimore, MD
    MS-Off Ver
    2010
    Posts
    6

    Re: Loop through Excel sheets and copy range to Powerpoint, Almost there!!

    I have managed to figure out its is in fact copying the range to the clipboard properly, however it is not pasting it. I'm not sure why.

+ 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 range in excel and paste in Powerpoint VBA
    By JeradAllan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-04-2017, 08:49 AM
  2. [SOLVED] Copy Range (B2&B3) from excel to a textbox in Powerpoint
    By IonutC in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-01-2016, 06:30 AM
  3. vba copy excel range to powerpoint ran error
    By ermai in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-09-2016, 08:00 AM
  4. Loop copy paste from excel to powerpoint
    By lupingamon in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-03-2014, 08:52 AM
  5. Loop copy paste from excel to powerpoint
    By lupingamon in forum PowerPoint Formatting & General
    Replies: 0
    Last Post: 07-02-2014, 09:41 AM
  6. 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
  7. 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

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