I am trying to upload info into SAP GUI from Excel data. The VBA script runs, but the problems are below:
- It will only work on rows 10-90 flawlessly. If I need it to be above row 90, I get an error.
- See the example below - If one of the rows is missing then I am off by one row the entire time.
Any help would be great!
Code:
If Not IsObject(Application) Then
Set SapGuiAuto = GetObject("SAPGUI")
End If
If Not IsObject(session) Then
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject Application, "on"
End If
session.findById("wnd[0]").ResizeWorkingPane 150, 26, False
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nzsd_reqord"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtS_VBELN-LOW").Text = salesdoc1
session.findById("wnd[0]/usr/ctxtS_VBELN-LOW").caretPosition = 7
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/shellcont/shell").setCurrentCell -1, "POSNR"
session.findById("wnd[0]/shellcont/shell").SelectColumn "POSNR"
session.findById("wnd[0]/shellcont/shell").PressToolbarButton "&FIND"
session.findById("wnd[1]/usr/txtGS_SEARCH-VALUE").Text = itemnumber
session.findById("wnd[1]/usr/cmbGS_SEARCH-SEARCH_ORDER").Key = "0"
session.findById("wnd[1]/usr/txtGS_SEARCH-VALUE").caretPosition = 2
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]").Close
Dim rowNr As Long
Dim rg As Range
Set rg = Range("B2") 'the cell in question
Select Case rg.Value
Case Is <= 90: rowNr = Left(rg.Value, 1) - 1
Case 100: rowNr = 10
End Select
session.findById("wnd[0]/shellcont/shell").ModifyCell rowNr, "EINTREFF", deldate
session.findById("wnd[0]/shellcont/shell").ModifyCell rowNr, "BEGRU1", reason
session.findById("wnd[0]/shellcont/shell").ModifyCell rowNr, "BEGRU2", Bizpurpose
session.findById("wnd[0]/shellcont/shell").CurrentCellColumn = "BEGRU2"
session.findById("wnd[0]/shellcont/shell").FirstVisibleColumn = "OFMNG"
session.findById("wnd[0]/shellcont/shell").ClearSelection
session.findById("wnd[0]/tbar[0]/btn[11]").press
session.findById("wnd[1]/usr/btnBUTTON_1").press