0

I need to get values from an existing Excel sheet and transfer them t SAP GUI. This is done by an vbscript and works. But I need to get a loop this is where I am struggeling.

The loop should start from the second line.

Excel sample

The code below is not entering the values into SAP GUI.

Can someone please give an advice?

Thanks in advance.

Dim arrExcelValues()
i = 7
x = 0
    
Do Until objExcel.Cells(i,"N").Value = ""
    
    ReDim Preserve arrExcelValues(x)
    arrExcelValues(x) = objExcel.Cells(i, "N").Value
    
    i = i + 1
    x = x + 1

Loop

For Each werk in arrExcelValues

    session.findById("wnd[0]/tbar[0]/okcd").text = "mm01"
    session.findById("wnd[0]").sendVKey 0
    session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").text = (objSheet.Cells(46,"F").Value)
    session.findById("wnd[0]/usr/ctxtRMMG1_REF-MATNR").text = (objSheet.Cells(46,"F").Value)
    session.findById("wnd[0]/usr/ctxtRMMG1_REF-MATNR").setFocus
    session.findById("wnd[0]/usr/ctxtRMMG1_REF-MATNR").caretPosition = 8
    session.findById("wnd[0]").sendVKey 0
    session.findById("wnd[1]").sendVKey 0
    
    ' ************************************* here comes the problem
    session.findById("wnd[1]/usr/ctxtRMMG1-WERKS").text = (objSheet.Cells(werk,"N").Value)
    session.findById("wnd[1]/usr/ctxtRMMG1-VKORG").text = (objSheet.Cells(werk,"O").Value)
    ' ************************************* "erstes" Werk
    session.findById("wnd[1]/usr/ctxtRMMG1_REF-WERKS").text = (objSheet.Cells(6,"N").Value)
    session.findById("wnd[1]/usr/ctxtRMMG1_REF-VKORG").text = (objSheet.Cells(6,"O").Value)
    session.findById("wnd[1]/usr/ctxtRMMG1-VKORG").setFocus
    session.findById("wnd[1]/usr/ctxtRMMG1-VKORG").caretPosition = 4
    session.findById("wnd[1]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    
' ************************************* here comes the problem
session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP06/ssubTABFRA1:SAPLMGMM:2000/subSUB5:SAPLZMM_GINCOFIELDS:5802/ctxtMARC-PRCTR").text = (objSheet.Cells(werk,"P") & (objSheet.Cells(38,"P")).Value)
    session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP06/ssubTABFRA1:SAPLMGMM:2000/subSUB5:SAPLZMM_GINCOFIELDS:5802/ctxtMARC-PRCTR").setFocus
    session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP06/ssubTABFRA1:SAPLMGMM:2000/subSUB5:SAPLZMM_GINCOFIELDS:5802/ctxtMARC-PRCTR").caretPosition = 6
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    session.findById("wnd[0]/tbar[0]/btn[0]").press
    session.findById("wnd[1]/usr/btnSPOP-OPTION1").press
    session.findById("wnd[0]/tbar[0]/btn[15]").press
    
Next
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Marek
  • 1
  • 1
  • Is there an error message? Where is objSheet defined? – Andy G Jan 16 '18 at 09:34
  • No, no error message. It enters empty values into SAP and that fails afterwards. As this code is just a snippet at the beginnig of this script all should be defined `Dim objExcel Dim objSheet, intRow, i Set objExcel = GetObject(,"Excel.Application") Set objSheet = objExcel.ActiveWorkbook.ActiveSheet` – Marek Jan 16 '18 at 09:49
  • I am absolutely sorry...indeed there is an error message (to much trying around) it says Typeconflict 800A000D in this line `session.findById("wnd[1]/usr/ctxtRMMG1-WERKS").text = (objSheet.Cells(werk,"N").Value)` – Marek Jan 16 '18 at 10:41
  • What does the content of the variable called werk look like? – ScriptMan Jan 17 '18 at 11:56

0 Answers0