Search code examples
excelvbapowerpoint

Paste Excel range as Picture to Power Point


I have these below two codes and i am trying that when i run the code from Excel then mentioned range should be pasted as picture to PowerPoint.

But i really do not know how to do this. I googled and searched a lot but nothing find your help will be appreciated.

Sub convertaspicture()

Application.CutCopyMode = True

Worksheets("Pivot").Range("FC3:FP35").Copy

.Pictures.Paste
End With

Application.CutCopyMode = False


End Sub


Sub CopyToPowerPoint()
 Dim PPT As Object
    Set PPT = CreateObject("Powerpoint.Application")
    PPT.Visible = True
    PPT.Presentations.Open Filename:="C:\Topline\Topline Writeup.pptx"
    Set PPT = Nothing
End Sub

Receiving an error:

enter image description here

enter image description here


Solution

  • Copying a Range as Image is done using the CopyRange-Method

    Pasting the image into a Powerpoint Presentation is done using PasteSpecial. The following code gives you the idea, it puts the image on the first slide and moves it around a little bit.

    Sub testSub()
        Const ppFileName = "C:\Topline\Topline Writeup.pptx"
    
        Dim PPT As Object
        Set PPT = CreateObject("Powerpoint.Application")
        PPT.Visible = True
        ' Use this if file already exists:
        ' PPT.Presentations.Open Filename:=ppFileName
        ' Use this if you want to create a new file:
        PPT.Presentations.Add
        PPT.ActivePresentation.slides.Add Index:=1, Layout:=12 
    
        Worksheets("Pivot").Range("FC3:FP35").CopyPicture Appearance:=xlScreen, Format:=xlPicture
        With PPT.ActivePresentation.Slides(1)
            .Shapes.PasteSpecial
            With .Shapes(.Shapes.Count)
                .Left = 200
                .Top = 100
                .Width = 500
            End With
        End With
        ' Use this if you want to save an already existing file:
        ' PPT.ActivePresentation.Save
        ' Use this if you want to create a new file:
        PPT.ActivePresentation.SaveAs ppFileName  
        PPT.Quit
        Set PPT = Nothing
    
    End Sub
    

    Update: If you want to create a new PPT-file, use the command Add (instead of Open) and SaveAs to save the file

    PPT.Presentations.Add ' <-- No filename here!
    ..
    PPT.ActivePresentation.SaveAs  ppFileName