' Lesson 5: loop over company codes in Sheet1 A2:A10, run a report and export each to a file (paths/ids are examples).
Option Explicit
Sub ExportForEachCompany()
    Dim session As Object, r As Long, cc As String, msg As String
    Set session = GetObject("SAPGUI").GetScriptingEngine.Children(0).Children(0)
    For r = 2 To 10
        cc = Trim(ThisWorkbook.Sheets(1).Cells(r, 1).Value)
        If cc = "" Then Exit For
        session.findById("wnd[0]/tbar[0]/okcd").Text = "/nSE16N"
        session.findById("wnd[0]").sendVKey 0
        session.findById("wnd[0]/usr/ctxtGD-TAB").Text = "T001"
        session.findById("wnd[0]").sendVKey 0
        session.findById("wnd[0]/tbar[1]/btn[8]").press
        msg = session.findById("wnd[0]/sbar").Text      ' status bar message
        ThisWorkbook.Sheets(1).Cells(r, 2).Value = IIf(msg = "", "Done", msg)
        ' Export: List > Export > Spreadsheet differs by report; record it once and paste the lines here.
    Next r
End Sub
