(Solved) – Automation VBA script for task automation

Sub Visual()
    Const PER_ROW As Long = 3  'chart images per row on slide
    Dim PowerPointApp As Object
    Dim myPresentation As Object
    Dim mySlide As Object
    Dim myShape As Object
    Dim t As Long, l As Long, i As Long

    If PowerPointApp Is Nothing Then _
    Set PowerPointApp = CreateObject(class:="PowerPoint.Application")

    On Error GoTo 0

    Application.ScreenUpdating = False

    Set myPresentation = PowerPointApp.Presentations.Add
    Set mySlide = myPresentation.Slides.Add(1, 11)

    t = 100  'starting top
    l = 100  'starting left
    i = 0
    For Each co In ActiveSheet.ChartObjects
        i = i   1
        Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
        myShape.Left = l
        myShape.Top = t
        'set positions for next paste
        If i Mod PER_ROW = 0 Then
            l = l   100     'for example
            l = 100
            t = t   100
        End If
    Next co

    PowerPointApp.Visible = True
    Application.CutCopyMode = False
End Sub

In the code above the graph are being pasted adjacently in a vertical fashion however, can we have them pasted horizontally instead adjacent to one another without any overlap.

Leave a Reply

Your email address will not be published. Required fields are marked *