简体   繁体   中英

Excel VBA SAP GUI Scripting to find row index

I am trying to change resource in SAP via excel macro. I need to find the row number of the focused cell and then insert a 'work shift' row. I have already tried .CurrentCellRow , .SelectedRows & .GetRowPosition but unsuccessful.

Following is code I wrote till now,

   Sub SAP_Entry_Plus(i As Variant)

   Dim STime As String
   Dim FTime As String
   Dim CU As String

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

            SlcDate = ThisWorkbook.Worksheets("Planned Shifts").Range("C" & i).Value
            x = (Weekday(SlcDate, vbMonday) - 1)
            MonDate = SlcDate - x

        Session.findById("wnd[1]/usr/ctxtRC68K-DATUV_SEL").Text = MonDate
        Session.findById("wnd[1]/tbar[0]/btn[0]").press

        RNum2 = Session.findById("wnd[0]/usr/tblSAPLCRK0TC116").CurrentCellRow
        RNum3 = Session.findById("wnd[0]/usr/tblSAPLCRK0TC116").SelectedRows
        RNum4 = Session.findById("wnd[0]/usr/tblSAPLCRK0TC116").GetRowPosition
        RNum5 = Session.findById("wnd[0]/usr/tblSAPLCRK0TC116").GetSelectedCellRow
        RNum6 = Session.findById("wnd[0]/usr/tblSAPLCRK0TC116").GetCurrentCellRow


        Session.findById("wnd[0]/usr/tblSAPLCRK0TC116").getAbsoluteRow(123).Selected = True

        Session.findById("wnd[0]/usr/tblSAPLCRK0TC116/ctxtKAZA-KKOPF[2,6]").SetFocus
        Session.findById("wnd[0]/tbar[1]/btn[6]").press

            STime = Format(ThisWorkbook.Worksheets("Planned Shifts").Range("D" & i).Value, "hh:mm:ss")
            FTime = Format(ThisWorkbook.Worksheets("Planned Shifts").Range("E" & i).Value, "hh:mm:ss")
            CU = ThisWorkbook.Worksheets("Planned Shifts").Range("F" & i).Value

        Session.findById("wnd[0]/usr/tblSAPLCRK0TC116/ctxtKAZA-BEGZT[8," & x + 1 & "]").Text = STime
        Session.findById("wnd[0]/usr/tblSAPLCRK0TC116/ctxtKAZA-ENDZT[9," & x + 1 & "]").Text = FTime
        Session.findById("wnd[0]/usr/tblSAPLCRK0TC116/txtKAZA-NGRAD[11," & x + 1 & "]").Text = CU

    End Sub

You could try to solve with the following parameters:

set myTable = session.findById("wnd[0]/usr/tblSAPLCRK0TC116")

myRow = myTable.CurrentRow
myNumber_of_Rows = myTable.RowCount
myVis_Rows = myTable.VisibleRowCount
myPosition = myTable.VerticalScrollbar.Position

myAbsolute_Row = myPosition + myRow

The following link might also help a bit: https://documentation.microfocus.com/help/index.jsp?topic=%2Fcom.borland.silktest.silk4net.doc%2Flangref%2FSAP%2FSapTableClass_ref.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM