<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Script cannot get data from Excel with VBA in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/script-cannot-get-data-from-excel-with-vba/m-p/12054804#M1969006</link>
    <description>&lt;P&gt;HI All，&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;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.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;all codes as below, could you please help have a check and reply me what can I do then,&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;thanks in advance.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1758530-2019-12-22-150546.png" /&gt;&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt; 

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 &amp;gt; 1 Then
session.findById("wnd[1]/usr/btnSPOP-VAROPTION1").press
End If
session.findById("wnd[0]").sendvkey 0
If session.Children.Count &amp;gt; 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 &amp;gt; 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

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 22 Dec 2019 09:03:11 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2019-12-22T09:03:11Z</dc:date>
    <item>
      <title>Script cannot get data from Excel with VBA</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/script-cannot-get-data-from-excel-with-vba/m-p/12054804#M1969006</link>
      <description>&lt;P&gt;HI All，&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;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.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;all codes as below, could you please help have a check and reply me what can I do then,&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;thanks in advance.&lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt; &lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1758530-2019-12-22-150546.png" /&gt;&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt; 

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 &amp;gt; 1 Then
session.findById("wnd[1]/usr/btnSPOP-VAROPTION1").press
End If
session.findById("wnd[0]").sendvkey 0
If session.Children.Count &amp;gt; 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 &amp;gt; 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

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Dec 2019 09:03:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/script-cannot-get-data-from-excel-with-vba/m-p/12054804#M1969006</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-12-22T09:03:11Z</dc:date>
    </item>
  </channel>
</rss>

