new entries into a table using vbs on Excel spreadsheet to SM30 on SAP
new entries into a table using vbs on Excel spreadsheet to SM30 on SAP
Section titled “new entries into a table using vbs on Excel spreadsheet to SM30 on SAP”Working on SAP Security, I’ve come up to some instances in which a script would help a lot! :wink:
This is one of those instances.
!!! note Enter this in a module on the Excel workbook you’re working with.
Also, be sure to trace once with the SAPGUI script recorder to getthe values for `<saptable>` and `<saptablefield>`.
Timer code can be removed/commented before execution.Sub sm30newentriesTABLE()
'' new entries on TABLE'
' timer code to count time taken on scriptDim StartTime As DoubleStartTime = Timer
'''''''''''''''''''' 'Your Code' ''''''''''''''''''''' timer code to count time taken on script
' variablesDim i, role, roleDescription, pSecondary, pPrimary' variables
' sapgui connectionSet SapGuiAuto = GetObject("SAPGUI")Set SapApplication = SapGuiAuto.GetScriptingEngineSet Connection = SapApplication.Children(0)Set session = Connection.Children(0)' sapgui connection
'go into tcodesession.findById("wnd[0]/tbar[0]/okcd").Text = "/nSM30"session.findById("wnd[0]/tbar[0]/btn[0]").presssession.findById("wnd[0]/usr/ctxtVIEWNAME").Text = "tablename"session.findById("wnd[0]/usr/btnUPDATE_PUSH").presssession.findById("wnd[0]/tbar[1]/btn[5]").press
'get data from current active sheet in the opened workbookFor i = 2 To Cells.Find("*", Range("A1"), xlFormulas, , xlByRows, xlPrevious).Row'set variables values for each rowroleS = Cells(i, 1).ValueroleDescription = Cells(i, 2).ValuepSecondary = Cells(i, 10).ValuepPrimary = Cells(i, 11).Value
'do new entriessession.findById("wnd[0]/<saptable>/<saptablefield>").Text = roleSsession.findById("wnd[0]/<saptable>/<saptablefield>").Text = roleDescriptionsession.findById("wnd[0]/<saptable>/<saptablefield>").Key = "Y"session.findById("wnd[0]/<saptable>/<saptablefield>").Key = "Y"session.findById("wnd[0]/<saptable>/<saptablefield>").Key = "PR1"session.findById("wnd[0]/<saptable>/<saptablefield>").Text = pSecondarysession.findById("wnd[0]/<saptable>/<saptablefield>").Text = pPrimarysession.findById("wnd[0]/<saptable>/<saptablefield>").Key = "PWM"
'move one vertical scroll step downsession.findById("wnd[0]/<saptable>").verticalScrollbar.Position = i - 1
Next
' timer code to count time taken on scriptMsgBox "RunTime : " & Format((Timer - StartTime) / 86400, "hh:mm:ss")' timer code to count time taken on script
End Sub