Consulting

Results 1 to 7 of 7

Thread: Copying excel ranges to powerpoint

  1. #1
    VBAX Newbie
    Joined
    Nov 2017
    Posts
    3
    Location

    Post Copying excel ranges to powerpoint

    Hello guys,

    I am new in VBA programming and I needed some help. My problem consists of copying excel ranges (from 1 to n), to powerpoint slides, wich are macro-named according to product name. I have tried the code below:

    But this one copies my range to a new slide in my open powerpoint. How can I do to copy & paste it to the slide I have renamed (with macro)? Also another issue, how can I copy filtered ranges, in order to have the same header of the table?

    Sub ExcelRangeToPowerPoint()
    
    
    Dim rng As Range
    Dim PowerPointApp As Object
    Dim myPresentation As Object
    Dim mySlide As Object
    Dim myShape As Object
    
    
    'Copy Range from Excel
      Set rng = ThisWorkbook.ActiveSheet.Range("(c2:h5)")
    
    
    'Create an Instance of PowerPoint
      On Error Resume Next
        
        'Is PowerPoint already opened?
          Set PowerPointApp = GetObject(Class:="PowerPoint.Application")
        
        'Clear the error between errors
          Err.Clear
    
        'If PowerPoint is not already open then open PowerPoint
          If PowerPointApp Is Nothing Then Set PowerPointApp = CreateObject(Class:="PowerPoint.Application")
        
        'Handle if the PowerPoint Application is not found
          If Err.Number = 429 Then
            MsgBox "PowerPoint could not be found, aborting."
            Exit Sub
          End If
    
      On Error GoTo 0
    
    
    'Optimize Code
      Application.ScreenUpdating = False
       
       'Reference active presentation
      Set myPresentation = PowerPointApp.ActivePresentation
     
      Set mySlide = myPresentation.Slides.Add(1, 11) '11 = ppLayoutTitleOnly
    
     
    'Copy Excel Range
      rng.Copy
     
     
    'Paste to PowerPoint and position
      mySlide.Shapes.PasteSpecial DataType:=2  '2 = ppPasteEnhancedMetafile
      Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
      
       
        'Set position:
          myShape.Left = 180
          myShape.Top = 350
    
    
    'Make PowerPoint Visible and Active
      PowerPointApp.Visible = True
      PowerPointApp.Activate
    
    
    'Clear The Clipboard
      Application.CutCopyMode = False
         
    End Sub
    Thanks in advance
    Last edited by SamT; 11-23-2017 at 07:22 AM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Moderator Bump
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    What do you mean by filtered ranges ?
    Can you post a sample Excel file to illustrate what you mean ?

  4. #4
    VBAX Newbie
    Joined
    Nov 2017
    Posts
    3
    Location
    Hello snb, thank you for your reply. This is my example. Now I want to copy the header of the table and data range for prod 1 in a powerpoint slide, then the header of the table ande data range for prod 2 in a different powerpoint slide. I have many products and examples like this one below. So how can I do it automatically via VBA?

    Capture.jpg

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    This is not an Excel file, but .jpg.

  6. #6
    VBAX Newbie
    Joined
    Nov 2017
    Posts
    3
    Location
    Here is the excel file.
    Attached Files Attached Files

  7. #7
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Start removing all merged cells.
    Start always using cel A1 (row 1 & column 1)
    Start using an intelligent Table in Excel.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •