cancel
Showing results for 
Search instead for 
Did you mean: 

SAPGUI COMBOBOX SELECTION FAILS IN VBA

Former Member
0 Kudos

Hi everyone,

I am trying to enter some data in SAP PRA module through excel VBA. Upon recording script and putting in excel macro, i am experiencing VBA runtime error-613 "Method has got an invalid argument". There is a combo box control, which has to be set to a key "11F4", but the combobox does not load any list while executing through VBA.

Below is the code, kindly help

Dim sapguiapp As Object, oconnection As Object, sapsesi As Object

If sapguiapp Is Nothing Then

    Set sapguiapp = CreateObject("Sapgui.ScriptingCtrl.1")

    

    End If

If oconnection Is Nothing Then

    Set oconnection = sapguiapp.OpenConnection("RP1 [ICE-Other Module]", True)

End If

If sapsesi Is Nothing Then

    Set sapsesi = oconnection.Children(0)

End If

With sapsesi

.findById("wnd[0]").iconify

.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "500"

.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "91984"

.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "mindblow"

.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"

.findById("wnd[0]/tbar[0]/btn[0]").press

23 If .Children.Count > 1 Then

.findById("wnd[0]").sendVKey 0

End If

If .Children.Count > 1 Then GoTo 23 Else GoTo 24

24 .findById("wnd[0]").iconify

   .findById("wnd[0]").sendVKey 0

    .findById("wnd[0]").maximize

If IsObject(wscript) Then

  wscript.ConnectObject session, "on"

   wscript.ConnectObject Application, "on"

End If

.findById("wnd[0]").maximize

.findById("wnd[0]/tbar[0]/okcd").Text = "ZPRARECDWNHRS"

.findById("wnd[0]").sendVKey 0

.findById("wnd[0]/usr/radG_S_SELECTION-OFFSHORE").Select

.findById("wnd[0]/usr/cmbG_S_SELECTION-WERKS").SetFocus

''below is the line where error occurs

.findById("wnd[0]/usr/cmbG_S_SELECTION-WERKS")..key="11F4"

.findById("wnd[0]").sendVKey 0

                        I tried whatever i could, but no success.Please help

                         Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

holger_khn
Contributor
0 Kudos

Hello.

I can see you open a session with Sapgui.ScriptingCtrl.1 object. This have not same Options as an session opened with SAPGUI direct. I guess you use an script recording from a normal session. This could be why it fail. May you should adopt yourVBA code to an existing session and check if this will solve your issue.

Former Member
0 Kudos

HI, thanks for the reply. Please tell me if i need to add some references to VBA to get the desired result. I have earlier made a project, where i log in to sap through excel vba userform in a way that the user never knows that sap window is actually active anytime and data entry is done into sap. I want the similar kind of project to be done this time, but am stuck with combo box selection error. Plese help me.

regards

   raj kumar pathak

Former Member
0 Kudos

Do u mean getobject method instead of create object method?