(Solved) – Automation VBA script for task automation

(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
        co.Chart.ChartArea.Copy
        mySlide.Shapes.Paste
        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
        Else
            l = 100
            t = t   100
        End If
    Next co

    PowerPointApp.Visible = True
    PowerPointApp.Activate
    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 *