VBA for SAP

Get ID & Text of each control in SAP window

Sub Get_SAP_TableIDs()

    Dim SapGuiAuto As Object
    Dim SAPApp As Object
    Dim SAPCon As Object
    Dim session As Object
    Dim ctrl As Object    

    ' define objects
    Set SapGuiAuto = GetObject("SAPGUI")
    Set SAPApp = SapGuiAuto.GetScriptingEngine
    Set SAPCon = SAPApp.Children(0)
    Set session = SAPCon.Children(0)    

    ' Search all the controls on SAP screen
    For Each ctrl In session.FindById("wnd[0]/usr").Children
        Debug.Print ctrl.ID
        Debug.Print ctrl.Text
'        If InStr(1, ctrl.ID, "tbl") > 0 Or InStr(1, ctrl.ID, "shell") > 0 Then
'            Debug.Print "Possible Table/Grid ID: " & ctrl.ID & " | Type: " & ctrl.Type
'        End If
    Next ctrl

    MsgBox "Check Immediate Window (Ctrl+G) for result"

End Sub


Other VBA codes for SAP

'new window
session.findById("wnd[0]/tbar[0]/okcd").Text = "/n"

'enter T-code
session.findById("wnd[0]/tbar[0]/okcd").Text = "su3"

'press enter key
session.findById("wnd[0]").sendVKey 0

'Click on Generate/Replace file button
If Len(Dir(OutputPathSAP & Application.PathSeparator & "Closing balance" & ".xlsx")) = 0 Then
    session.findById("wnd[1]/tbar[0]/btn[0]").Press
Else
    session.findById("wnd[1]/tbar[0]/btn[11]").Press
End If

'Code to By-pass Information windows
Do While session.ActiveWindow.Text Like "*Information"
    session.findById("wnd[1]/tbar[0]/btn[0]").press
Loop

एक टिप्पणी भेजें

0 टिप्पणियाँ