Search code examples
excelvbapowerpoint

Pasting Range from Excel to Ppt as image


Hi have a code that Copy Range from Excel to Ppt as image. However when I give command for it to resize Height width top left it is not doing it bcoz of default setting of Lock Aspect ratio. Is there any way I can modify my code.


Solution

  • Set .LockAspectRatio property of the shape to msoFalse

    Option Explicit
    
    Sub ppt()
    
        Dim PPTApp As PowerPoint.Application
        Dim PPTPres As PowerPoint.Presentation
        Dim PPTSlide As PowerPoint.Slide
        
        Set PPTApp = New PowerPoint.Application
        PPTApp.Visible = True
        Set PPTPres = PPTApp.Presentations.Add
        Set PPTSlide = PPTPres.Slides.Add(1, ppLayoutBlank)
    
        Range("A1:C10").Copy
        With PPTSlide.Shapes.PasteSpecial(ppPasteMetafilePicture)
            .LockAspectRatio = msoFalse
            .Left = 20
            .Top = 20
            .Width = 400
            .Height = 300
        End With
        
    End Sub