Selecting a Node in SAP in Excel While Loop

bellg

New Member
Joined
May 13, 2014
Messages
29
This is some recorded code from SAP to select a node within a VA03/CU51 transaction.

Code:
If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = application.Children(0)
End If
If Not IsObject(session) Then
   Set session    = connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session,     "on"
   WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/shellcont/shell").selectedNode = "00000003"
session.findById("wnd[0]/shellcont/shell").doubleClickNode "00000003"

I'm looking to run a while loop that selects and deletes certain nodes.

Code:
    Dim i As Integer
    Dim substring As String
    
    i = 1
    Do While Session.findById("wnd[0]/shellcont/shell").getNodeTextByPath("1\" & i) <> "" ' loops through all nodes
        substring = Session.findById("wnd[0]/shellcont/shell").getNodeTextByPath("1\" & i) ' sets a string equal to the current node's text value
        
        If Left(substring, 3) = "333" Then


            If ActiveCell.Offset(0, 15).Value = "" Then
                    MsgBox ("yay")
            Else
                    MsgBox ("whoah")
            End If
            
            Session.findById("wnd[0]/shellcont/shell").selectedNodeFullPath ("1\" & i) '** I can't get this line to select the current node
            Session.findById("wnd[0]/tbar[1]/btn[14]").press ' deletes current node
            
        End If
        i = i + 1
    Loop

I want to be able to select the current node within my while loop. How can I do this?

Thanks, Greg
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,215,750
Messages
6,126,666
Members
449,326
Latest member
asp123

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top