+ Reply to Thread
Results 1 to 14 of 14

Pasting Selected Ranges into a PowerPoint Slides

Hybrid View

  1. #1
    Registered User
    Join Date
    03-16-2009
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Pasting Selected Ranges into a PowerPoint Slides

    You will find two attachements to this thread. One is a completed example I found pasting charts into PowerPoint Presentation and the other is my example of what I would like done. Difference here is that I am not using charts, instead I am using selected ranges to paste in a PowerPoint Presentation.

    Instead of pasting charts to Excel, I would like to make each colored range a slide in the PowerPoint (Please see attachment).

    So by click on the command button "Create PowerPoint Presentation", I would like to have PowerPoint open and the two colored ranges should be in the PowerPoint Presentation as Slide 1 and Slide2.

    I have done some research on this topic and found information, but I have not clue as how to do it.
    Attached Files Attached Files
    Last edited by NaNaBoo; 04-02-2009 at 10:58 AM. Reason: Marking As Solved

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Pasting Selected Ranges into a PowerPoint Slides

    Did you want ranges as slide or Shapes as slides? The 2nd xls has two rectangle shapes.

    This example copies 4 ranges as images to slides.
    Sub CreatePPoint()
      Dim pPoint As Object    'PowerPoint.Application
      Dim pPres As Object     'PowerPoint.Presentation
      Dim pSlide As Object    'PowerPoint.Slide
      Dim pShape As Object    'PowerPoint.ShapeRange
      Dim pAvg As Object      'PowerPoint.Shape
    
      Dim Cht As Chart
      Dim Pivot As PivotTable
      Dim PItem As PivotItem
      Dim PivotData As Range
      Dim Avg As Double
      Dim r As Range, ar
      Set r = Range("A2:D21,A22:D41,A42:D61,A62:D81")
      'Turn off screen updating
      Application.ScreenUpdating = False
    
      'Create a new PowerPoint presentation (and application)
      'New PowerPoint.Application
      Set pPoint = CreateObject("PowerPoint.Application")
      
      Set pPres = pPoint.Presentations.Add
    
      'Loop through each of the items of the page field
      For Each ar In r.Areas
          If pPres.Slides.Count = 0 Then
            Set pSlide = pPres.Slides.Add(1, 12)    'ppLayoutBlank = 12
          Else
            Set pSlide = pPres.Slides.Add(pPres.Slides.Count + 1, _
                12)      'ppLayoutBlank
          End If
    
          'Copy an image of the chart
          ar.CopyPicture Appearance:=xlPrinter, Format:=xlPicture
    
          'Paste it in PowerPoint
          Set pShape = pSlide.Shapes.Paste
    
          'Resize it
          With pShape
            .ScaleWidth 1, msoFalse, msoScaleFromTopLeft
            .ScaleHeight 0.94, msoFalse, msoScaleFromBottomRight
            .Left = 10
            .Top = 10
          End With
      Next ar
    
      'Restore screen updating
      Application.ScreenUpdating = True
    
      'Activate and display PowerPoint
      pPoint.Visible = True
      pPoint.ActiveWindow.ViewType = 1    'ppViewSlide = 1
      pPoint.Activate
    
      'Destroy the variables
      Set pShape = Nothing
      Set pSlide = Nothing
      Set pPres = Nothing
      Set pPoint = Nothing
    End Sub
    Last edited by Kenneth Hobson; 03-31-2009 at 05:09 PM.

  3. #3
    Registered User
    Join Date
    03-16-2009
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Pasting Selected Ranges into a PowerPoint Slides

    This is exactly what I wanted. Now, I know that I may be asking for too much here.
    But when the ranges are sent to the PowerPoint Presentation as a picture object, its' size is bigger than the width and height of the PowerPoint slide. Is there a away to create a code that will resize the picture object to automatically fit evenly in the PowerPoint slide?

    Please see my new attachment with the problem I am having
    Last edited by NaNaBoo; 04-01-2009 at 11:57 AM.

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Pasting Selected Ranges into a PowerPoint Slides

    You wanted all the ranges on one slide?

    For each range in its own slide and sized to fit width I used this code. I added Early binding so you can change it back or add the reference or just add the line were I set the Range areas and the slide shape's Width. If Height is set 2nd, the width expands over the page width.

    If you wanted to include your rectangle shapes this will do it as well. In fact, we could code it to get the area ranges based on rectangular shapes over the ranges.
    Sub CreatePPoint()
      'Late Binding
      'Dim pPoint As Object    'PowerPoint.Application
      'Dim pPres As Object     'PowerPoint.Presentation
      'Dim pSlide As Object    'PowerPoint.Slide
      'Dim pShape As Object    'PowerPoint.ShapeRange
      'Dim pAvg As Object      'PowerPoint.Shape
      
      'Early Binding
      'Add Tools > References.. > Microsoft Powerpoint 11.0 Object Library
      Dim pPoint As PowerPoint.Application
      Dim pPres As PowerPoint.Presentation
      Dim pSlide As PowerPoint.Slide
      Dim pShape As PowerPoint.ShapeRange
      Dim pAvg As PowerPoint.Shape
      
      Dim r As Range, ar
      Set r = Range("A2:N20,A23:N39,A42:N58,A61:N77")
      
      'Turn off screen updating
      Application.ScreenUpdating = False
    
      'Create a new PowerPoint presentation (and application)
      'New PowerPoint.Application
      'Late Binding
      'Set pPoint = CreateObject("PowerPoint.Application")
      'Early Binding
      Set pPoint = New PowerPoint.Application
      
      Set pPres = pPoint.Presentations.Add
    
      'Loop through each of the items of the page field
      For Each ar In r.Areas
          If pPres.Slides.Count = 0 Then
            Set pSlide = pPres.Slides.Add(1, 12)    'ppLayoutBlank = 12
          Else
            Set pSlide = pPres.Slides.Add(pPres.Slides.Count + 1, _
                12)      'ppLayoutBlank
          End If
    
          'Copy an image of the chart
          ar.CopyPicture Appearance:=xlPrinter, Format:=xlPicture
    
          'Paste it in PowerPoint
          Set pShape = pSlide.Shapes.Paste
    
          'Resize it
          With pShape
            Debug.Print "width", .Width, pPres.PageSetup.SlideWidth
            .Left = 10
            .Top = 10
            .Height = pPres.PageSetup.SlideHeight - 20
            .Width = pPres.PageSetup.SlideWidth - 20
            '.ScaleWidth 1, msoFalse, msoScaleFromTopLeft 'Was 1
            '.ScaleHeight 1, msoFalse, msoScaleFromBottomRight  'Was 0.94
          End With
      Next ar
    
      'Restore screen updating
      Application.ScreenUpdating = True
    
      'Activate and display PowerPoint
      pPoint.Visible = True
      pPoint.ActiveWindow.ViewType = 1    'ppViewSlide = 1
      pPoint.Activate
    
      'Destroy the variables
      Set pShape = Nothing
      Set pSlide = Nothing
      Set pPres = Nothing
      Set pPoint = Nothing
    End Sub

  5. #5
    Registered User
    Join Date
    03-16-2009
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Pasting Selected Ranges into a PowerPoint Slides

    I hope I did not confuse you. Initially, I did ask for you to have all of the ranges be on individuals slides. I just wanted to have the option to also fit all of the ranges on one slide and size it to fit on the PowerPoint.

  6. #6
    Registered User
    Join Date
    03-16-2009
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Pasting Selected Ranges into a PowerPoint Slides

    When I copy and paste the new code into the previous Excel attachment, I get an error. The code does not work.

    Please try your code in the previous spreadsheet and let me know what happens on your end.

    Thanks

  7. #7
    Registered User
    Join Date
    03-16-2009
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Pasting Selected Ranges into a PowerPoint Slides

    Thanks for the reply. I will try your first suggestion and "unmerged" the cells. That is a good start. I will let you know what happens.

    Stay tune.

  8. #8
    Registered User
    Join Date
    03-16-2009
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Pasting Selected Ranges into a PowerPoint Slides

    Thank you Kenneth Hobson for all the hard work you put into this.

    I finally have gotten around to playing with your code and I was able to get all of the ranges to fit on the PowerPoint Slide. With excellent readability. It looks great!!

    Here is how I revised your code:

    Sub CreatePPoint()
      Dim pPoint As Object    'PowerPoint.Application
      Dim pPres As Object     'PowerPoint.Presentation
      Dim pSlide As Object    'PowerPoint.Slide
      Dim pShape As Object    'PowerPoint.ShapeRange
      Dim pAvg As Object      'PowerPoint.Shape
    
      Dim Cht As Chart
      Dim Pivot As PivotTable
      Dim PItem As PivotItem
      Dim PivotData As Range
      Dim Avg As Double
      Dim r As Range, ar
      Set r = Range("A2:q88")
      'Turn off screen updating
      Application.ScreenUpdating = False
    
      'Create a new PowerPoint presentation (and application)
      'New PowerPoint.Application
      Set pPoint = CreateObject("PowerPoint.Application")
      
      Set pPres = pPoint.Presentations.Add
    
      'Loop through each of the items of the page field
      For Each ar In r.Areas
          If pPres.Slides.Count = 0 Then
            Set pSlide = pPres.Slides.Add(1, 12)    'ppLayoutBlank = 12
          Else
            Set pSlide = pPres.Slides.Add(pPres.Slides.Count + 1, _
                12)      'ppLayoutBlank
          End If
    
          'Copy an image of the chart
          ar.CopyPicture Appearance:=xlPrinter, Format:=xlPicture
    
          'Paste it in PowerPoint
          Set pShape = pSlide.Shapes.Paste
    
          'Resize it
          With pShape
            .ScaleWidth 0.8, msoFalse, msoScaleFromTopLeft
            .ScaleHeight 0.5, msoFalse, msoScaleFromBottomRight
            .Left = 50
            .Top = 75
        
          End With
      Next ar
    
      'Restore screen updating
      Application.ScreenUpdating = True
    
      'Activate and display PowerPoint
      pPoint.Visible = True
      pPoint.ActiveWindow.ViewType = 1    'ppViewSlide = 1
      pPoint.Activate
    
      'Destroy the variables
      Set pShape = Nothing
      Set pSlide = Nothing
      Set pPres = Nothing
      Set pPoint = Nothing
    End Sub

+ Reply to Thread

LinkBacks (?)

  1. Page
    Refback This thread
    10-04-2013, 05:52 AM

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