Skip to Content
0

Transfer Data from Excel to SAP

Nov 24, 2016 at 01:47 PM

143

avatar image

I found an old thread concerning transfer data from Excel to a SAP transaction (

https://archive.sap.com/discussions/thread/1699675)

Solution from ScriptMan works great, however in my case I think some finetuning is still possible; This is a part of my code:

For i = 2 To xclapp.ActiveCell.SpecialCells(11).Row
    For j = 1 To xclapp.ActiveCell.SpecialCells(11).Column
        If j = 1 Then Dienst = xclsht.Cells(i, j).Value
        If j = 3 Then Van = xclsht.Cells(i, j).Value
        If j = 4 Then Tot = xclsht.Cells(i, j).Value
        If j = 5 Then FTE = xclsht.Cells(i, j).Value
    Next
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nz6v0pm_ir02"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtP_ARBPL").Text = Dienst
session.findById("wnd[0]/usr/ctxtP_ARBPL").SetFocus
session.findById("wnd[0]/usr/ctxtP_ARBPL").caretPosition = 7
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/usr/tabsTABSTRIP/tabpCAPINV").Select
session.findById("wnd[0]/tbar[1]/btn[40]").press
session.findById("wnd[0]/usr/ctxtDATUV").Text = Van
session.findById("wnd[0]/usr/ctxtDATUB").Text = Tot
session.findById("wnd[0]/usr/txtANZHL").Text = FTE
session.findById("wnd[0]/usr/txtANZHL").SetFocus
session.findById("wnd[0]/usr/txtANZHL").caretPosition = 1
session.findById("wnd[0]/usr/btnBTN_OK").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
On Error Resume Next
Next
session.findById("wnd[0]/tbar[0]/btn[3]").press

In column 1 of my Excel file (j = 1;Dienst). The value has to be entered on the first screen of the transaction, values of the other cells have to be entered in the next screen. Values in column 1 are there multiple times and with this code I constantly enter this value, go to the next screen and enter the other values, and go back to the first screen. It would be better to stay in the last screen and only go back if there is a new value in column 1.

Any solution to do this?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Script Man Dec 01, 2016 at 08:23 AM
0

Hi Tim,

Unfortunately, I dont know the transaction. Nevertheless, I try to make a suggestion:

Dienst = ""
For i = 2 To xclapp.ActiveCell.SpecialCells(11).Row
    For j = 1 To xclapp.ActiveCell.SpecialCells(11).Column
        If j = 1 Then 
         Dienst_old = Dienst
         Dienst = xclsht.Cells(i, j).Value
        end if 
        If j = 3 Then Van = xclsht.Cells(i, j).Value
        If j = 4 Then Tot = xclsht.Cells(i, j).Value
        If j = 5 Then FTE = xclsht.Cells(i, j).Value
    Next

If Dienst_old <> Dienst then
 session.findById("wnd[0]/tbar[0]/okcd").Text = "/nz6v0pm_ir02"
 session.findById("wnd[0]").sendVKey 0
 session.findById("wnd[0]/usr/ctxtP_ARBPL").Text = Dienst
 'session.findById("wnd[0]/usr/ctxtP_ARBPL").SetFocus
 'session.findById("wnd[0]/usr/ctxtP_ARBPL").caretPosition = 7
 session.findById("wnd[0]").sendVKey 0
 session.findById("wnd[0]/tbar[1]/btn[8]").press
 session.findById("wnd[0]/usr/tabsTABSTRIP/tabpCAPINV").Select
 'I'm not sure if the following command should not be below.
 session.findById("wnd[0]/tbar[1]/btn[40]").press
end if

'One must test whether the following command would rather not belong here.
'session.findById("wnd[0]/tbar[1]/btn[40]").press

session.findById("wnd[0]/usr/ctxtDATUV").Text = Van
session.findById("wnd[0]/usr/ctxtDATUB").Text = Tot
session.findById("wnd[0]/usr/txtANZHL").Text = FTE
'session.findById("wnd[0]/usr/txtANZHL").SetFocus
'session.findById("wnd[0]/usr/txtANZHL").caretPosition = 1
session.findById("wnd[0]/usr/btnBTN_OK").press
session.findById("wnd[1]/tbar[0]/btn[0]").press
On Error Resume Next
Next
session.findById("wnd[0]/tbar[0]/btn[3]").press

Regards,

ScriptMan

Share
10 |10000 characters needed characters left characters exceeded
Tim Speleman Dec 08, 2016 at 12:12 PM
0

Thank you!

Works perfectly with line

'session.findById("wnd[0]/tbar[1]/btn[40]").press

after "end if"
Share
10 |10000 characters needed characters left characters exceeded