cancel
Showing results for 
Search instead for 
Did you mean: 

Excel VBA with GUIScripting - For each element

09-25-2019 8:02 AM
2521 views 3 comments
0 Likes
SAP Managed Tags
Subscribe

Hi All,

I am not sure if i am at the right platform to ask this question.

1) I will like to know if there is any place that i can read up on the respective property or function of the syntax.

For example, session.findById("wnd[0]").maximize, I extracted this from the output of the Script recording, I will like to know, what other function is there, or findById is the only function?

2) I will also like to check, if it is possible for me to use VBA to loop through all the element in the SAPGUI and return a value.

For example,

Dim X as object

For each X in Session.

If X.Text = "New Entries" then

....

End If

....

My objective is to find if whether the element exist on the screen or it is still loading.

Regards

David

0 Likes

Accepted Solutions (0)

Answers (2)

Answers (2)

daniel_mccollum
Active Contributor

This a chunk, not directly GUI related, but during the logon process to retrieve the list of systems in the logon pad.

It has some for each looping.

Function SAPUILandscape(system)

    Dim fpath                   As String
    Dim sapfiles                As String
    Dim SAPUILandscapefile      As String
    Dim ConnString              As String
    Dim id                      As Variant
    Dim isValid                 As Boolean
    Dim testing                 As Boolean
    Dim AttribName              As String
    Dim AttribServer            As String
    Dim CurrentXpath            As String
    Dim xmlDoc                  As MSXML2.DOMDocument60
    Dim xmlSelection            As MSXML2.IXMLDOMSelection
    Dim xmlAttributes           As MSXML2.IXMLDOMNamedNodeMap
    Dim xmlItems                As MSXML2.IXMLDOMAttribute

    Set xmlDoc = New MSXML2.DOMDocument60
    testing = False
    
    'xml structures
    AttribName = "name"
    AttribServer = "server"
    'alt AttribTag = "systemid"
    CurrentXpath = "//Landscape/Services/Service[@" & AttribName & "='" & system & "']"
    
    'find SAPUILandscape.xml
    fpath = Environ$("AppData")
    sapfiles = "SAP\Common\"
    SAPUILandscapefile = "SAPUILandscape.xml"

    If Right(fpath, 1) <> "\" Then
        fpath = fpath & "\"
    End If
    fpath = fpath & sapfiles & SAPUILandscapefile

    xmlDoc.async = False
    
    If xmlDoc.Load(fpath) Then
        'successfully loaded xml
        Set xmlSelection = xmlDoc.SelectNodes(CurrentXpath)
        If xmlSelection.Length = 0 Then
            'path not found
            isValid = False
        Else:
            Set xmlAttributes = xmlSelection.Item(0).Attributes
            For Each xmlItems In xmlAttributes
                If xmlItems.BaseName = AttribServer Then
                    ConnString = xmlItems.NodeValue
                    isValid = True
                    Exit For
                End If
            Next xmlItems

        End If
    
    Else:
        If testing = True Then
            ' The document failed to load.
            Dim strErrText As String
            Dim xPE As IXMLDOMParseError
            ' Obtain the ParseError object
            Set xPE = xmlDoc.parseError
            With xPE
                strErrText = "Your XML Document failed to load" & _
                  "due the following error." & vbCrLf & _
                  "Error #: " & .ErrorCode & ": " & xPE.reason & _
                  "Line #: " & .Line & vbCrLf & _
                  "Line Position: " & .linepos & vbCrLf & _
                  "Position In File: " & .filepos & vbCrLf & _
                  "Source Text: " & .srcText & vbCrLf & _
                  "Document URL: " & .Url
            End With
            
            MsgBox strErrText, vbExclamation
            isValid = False
        Else:
            isValid = False
        
        End If
        
    End If

    If isValid = True Then
        'connection found in landscape
        SAPUILandscape = formatConnString(ConnString)
        
    Else:
        'connection not found in landscape
        SAPUILandscape = ""
        
    End If

End Function

for the SAP gui, I dont have a sample quickly to hand sorry, but you can declare the variables as the specific types, then you can loop for each child object,

    Dim tobj                                As SAPFEWSELib.GuiTableControl
    Dim tObjChild                           As SAPFEWSELib.GuiComponentCollection

then for each loop

For Each tObjChild In tObj
	'logic here
Next tObjChild
Former Member
0 Likes

I managed to find the SAP GUI Scripting help file and sapfewse.ocx.

but I really keen to learn how to loop through the element/object in SAP

daniel_mccollum
Active Contributor