Automate PowerPoint by VBA

Creating powerpoint presentation of dashboard is a time taking process and it VBA can easily Automate PowerPoint.

As powerpoint also support VBA so the powerpoint object model can be loaded in  excel vba. here we are sharing a very basic example of how we can use ppt object model in to excel vba to send charts on a slide.

here is the code we are using

Sub SendChartToPowerPoint()
    Dim objPP As Object
    Dim objPresentation As Object
    Dim objSlides As Object
    Dim objChart As ChartObject
    Dim objShape As Object
    Dim strPath As String
    '--Load powerpoint by creating its object
    Set objPP = CreateObject("PowerPoint.Application")
    objPP.Visible = True
    '--Add a presentation
    Set objPresentation = objPP.presentations.Add
    '--add a blank slide to the presentation
    Set objSlides = objPresentation.slides.Add(1, 12)
    '--Loop all charts in the file
    For Each objChart In Sheet1.ChartObjects
        If objSlides Is Nothing Then
            Set objSlides = objPresentation.slides.Add(objPresentation.slides.Count + 1, 12)
        End If
        '--Copy chart as picture
        objChart.CopyPicture xlScreen, xlPicture
        '--Paste in powerpoint slide
        '-- Set height/width of the pasted shape
        Set objShape = objSlides.Shapes(objSlides.Shapes.Count)
        objShape.Height = 482
        objShape.Width = 855
        objShape.Top = 20
        objShape.Left = 61
        Set objSlides = Nothing
    Next objChart
End Sub

Join my VBA whatsApp group to know more

Contact us to get working fille