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
Bookmarks