Skip to Content
avatar image
Former Member

Selecting Item in Tree by Text

Hello all, thanks in advance for the assistance!

I am trying to write a script for SAP that I call from Excel, and I know from working with this for a few days now that finding the right syntax for things is not easy. Currently, I am working with transaction IH01 and have a tree (? I hope this is the right word for it) pulled up. Ideally, a user in Excel would type in or select something in English like "Bundler" and the item in the SAP tree with text "Bundler" would be selected. When I try to record a macro to find out what this item is called in SAP scripting, I get something like:


session.findById("wnd[0]/usr/cntlTREE_CONTAINER/shellcont/shell").selectItem "         24","1"


Does anybody know an alternative syntax so I do not have to manually build a database of these and use a lookup table in Excel? I'd ideally like to make this program reapplicable to different sets of "trees" and not have to go through the 300 entries in this tree and write down the  "         24","1" for each one!


Thanks!


Alex




Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Jun 09, 2014 at 06:53 PM

    Hi Alex.

    had the same Problem - so i wrote a Function that alternates through the tree using a simple for next Loop and looks for the text you are searching for:

    here is the Code:

    Public Function ermitteln(was)
    Set Tree = sapsession.findById("wnd[0]/usr/cntlTree_Container/shell/shellcont/shell")
    ermitteln = "0"
    For x = 0 To 300
    adummy = 11
    bdummy = adummy - Len(CStr(x))
    a = Space(bdummy) & CStr(x)
       
    On Error Resume Next
        Tree.selectItem a, "2"
        If Err.Number = 0 Then
            If Tree.GetItemText(a, "2") = was Then
                ermitteln = a
                Exit For
            End If
        End If
    Next
    End Function
    

    the Selection Routine looks as follows:

    node = ermitteln("Bundler")
    session.findById("wnd[0]/usr/cntlTREE_CONTAINER/shellcont/shell").selectItem " & node,"1"
    

    For Explanation:

    The Text i was looking for is in Item "2"

    so perhaps you have to Change it ...

    If there should be any Questions - go ahead ...

    hand

    Thomas B

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Thomas Bräutigam

      What should I do about line 2 which says that there is an "Object Required"?

      I tried changing to Set Tree = session.findbyId("wnd[0]/usr/cntlTree_Container/shell/shellcont/shell") and I also tried "wnd[0]/usr/cntlTREE_CONTAINER/shellcont/shell", but neither did work.

      Thank you for working me through this!