Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Script cannot get data from Excel with VBA

Former Member
0 Likes
1,101

HI All,

I did the following VBA code in Excel with SAP script code to access CO01 to looking forward the method for mass release, it can run perfect in the begins lines, but when it run to around line 10 SAP cannot get data for the next lines any more.

all codes as below, could you please help have a check and reply me what can I do then,

thanks in advance.

 

Sub EXCEL_to_SAP()
yes_No = MsgBox("Do you want to upload data into SAP really?", vbOKCancel)
If yes_No = 2 Then
  End
End If
   Set sapguiauto = GetObject("SAPGUI")
   Set SAPApp = sapguiauto.GetScriptingEngine
   Set Connection = SAPApp.Children(0)
   Set session = Connection.Children(0)
Dim i%
For i = 2 To 20 Step 1
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/NCO01"
session.findById("wnd[0]").sendvkey 0
session.findById("wnd[0]/usr/ctxtCAUFVD-MATNR").Text = Cells(i, 1)
On Error Resume Next
session.findById("wnd[0]/usr/ctxtCAUFVD-WERKS").Text = "7103"
session.findById("wnd[0]/usr/ctxtAUFPAR-PP_AUFART").Text = "PP01"
session.findById("wnd[0]/usr/ctxtAUFPAR-PP_AUFART").SetFocus
session.findById("wnd[0]/usr/ctxtAUFPAR-PP_AUFART").caretPosition = 4
session.findById("wnd[0]").sendvkey 0
session.findById("wnd[0]/usr/tabsTABSTRIP_0115/tabpKOZE/ssubSUBSCR_0115:SAPLCOKO1:0120/txtCAUFVD-GAMNG").Text = Cells(i, 2)
On Error Resume Next
session.findById("wnd[0]/usr/tabsTABSTRIP_0115/tabpKOZE/ssubSUBSCR_0115:SAPLCOKO1:0120/ctxtCAUFVD-GLTRP").Text = Cells(i, 3)
On Error Resume Next
session.findById("wnd[0]/usr/tabsTABSTRIP_0115/tabpKOZE/ssubSUBSCR_0115:SAPLCOKO1:0120/ctxtCAUFVD-GSTRP").Text = Cells(i, 4)
On Error Resume Next
session.findById("wnd[0]/usr/tabsTABSTRIP_0115/tabpKOZE/ssubSUBSCR_0115:SAPLCOKO1:0120/ctxtCAUFVD-GSTRP").SetFocus
On Error Resume Next
session.findById("wnd[0]/usr/tabsTABSTRIP_0115/tabpKOZE/ssubSUBSCR_0115:SAPLCOKO1:0120/ctxtCAUFVD-GSTRP").caretPosition = 10
session.findById("wnd[0]").sendvkey 0
session.findById("wnd[0]").sendvkey 0
session.findById("wnd[0]").sendvkey 0
session.findById("wnd[1]/usr/btnSPOP-VAROPTION1").press
If session.Children.Count > 1 Then
session.findById("wnd[1]/usr/btnSPOP-VAROPTION1").press
End If
session.findById("wnd[0]").sendvkey 0
If session.Children.Count > 1 Then
session.findById("wnd[1]/usr/btnSPOP-VAROPTION1").press
End If
session.findById("wnd[0]/tbar[0]/btn[11]").press
If session.Children.Count > 1 Then
session.findById("wnd[1]/usr/btnSPOP-OPTION1").press
  End If
   Cells(i, 5).Value = session.findById("wnd[0]/sbar/pane[0]").Text
    
   
Next i
End Sub

0 REPLIES 0