+ Reply to Thread
Results 1 to 3 of 3

Problem with VBA Code - Paste directly to PowerPoint Slide

  1. #1
    Registered User
    Join Date
    03-07-2017
    Location
    Brazil
    MS-Off Ver
    2010
    Posts
    7

    Question Problem with VBA Code - Paste directly to PowerPoint Slide

    Hey guys, good morning to everyone!

    I've been dealing a lot with powerpoint presentations lately so I searched the internet for a VBA code that allowed me to paste a specific selection directly to PPT from an Excel SpreadSheet. I came across with a code from another website (not sure if I can quote it here) and I adapted it a little bit, but I'm having an issue with the format of the image.

    I want to post it as a BITMAP, but whenever I try to do this, I just get a blank square in my PowerPoint slide. Other formats, like MetaFile Pictures or PNGs are working just fine. Any ideas?

    Sub Colar_Direto_PPT()

    Dim SelRange As Range
    Dim PowerPointApp As Object
    Dim myPresentation As Object
    Dim mySlide As Object
    Dim myShape As Object

    'Copy Range from Excel
    Set SelRange = Selection

    '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

    'Create a New Presentation
    Set myPresentation = PowerPointApp.ActivePresentation

    'Add a slide to the Presentation
    Set mySlide = PowerPointApp.ActiveWindow.View.Slide

    'Copy Excel Range
    SelRange.Copy

    'Paste to PowerPoint and position
    mySlide.Shapes.PasteSpecial (ppPasteMetafilePicture) <-- the part I'm having issues with
    Set myShape = mySlide.Shapes(mySlide.Shapes.Count)

    'Set position:
    myShape.Left = 66
    myShape.Top = 152

    'Make PowerPoint Visible and Active
    PowerPointApp.Visible = True
    PowerPointApp.Activate

    'Clear The Clipboard
    Application.CutCopyMode = False

    End Sub

  2. #2
    Forum Expert Tinbendr's Avatar
    Join Date
    06-26-2012
    Location
    USA
    MS-Off Ver
    Office 2010
    Posts
    2,125

    Re: Problem with VBA Code - Paste directly to PowerPoint Slide

    Try
    Please Login or Register  to view this content.
    David
    (*) Reputation points appreciated.

  3. #3
    Registered User
    Join Date
    03-07-2017
    Location
    Brazil
    MS-Off Ver
    2010
    Posts
    7

    Re: Problem with VBA Code - Paste directly to PowerPoint Slide

    Hey Tinbendr, thanks for the reply, but I solved it adding this line to the code just before the copy command.


    Application.ScreenUpdating = True


    'Copy Excel Range
    SelRange.Copy

+ 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. [SOLVED] Paste Range to duplicated Powerpoint slide not working the way i'd hoped. HELP!!!!!
    By Jschroeder71 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-15-2016, 07:59 AM
  2. Replies: 6
    Last Post: 08-18-2015, 06:39 AM
  3. [SOLVED] How to copy and paste 4 excel graphs into a single PowerPoint slide evenly?
    By Mirisage in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 03-07-2015, 12:47 AM
  4. Copy and paste some charts from excel into specific slide on a powerpoint template
    By ones4rus in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-23-2013, 03:00 AM
  5. macro to copy paste excel name range to powerpoint new slide
    By koi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-17-2013, 04:55 PM
  6. Paste multiple ranges by Inputbox and paste it on one slide in powerpoint
    By irfanparbatani in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-16-2012, 10:32 PM
  7. Replies: 0
    Last Post: 12-02-2011, 12:06 PM

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