Skip to Content

SAP GUI Scripting

Guys,

Am new to this scripting and am trying to mass upload some Maintenance plans in IP41. Recorded a script, but it gives an error " Object required" active workbook-. How can i fix this issue? Please see my script below.

Error is " Object required" active workbook

Code is as below:-

---------------------------------------------

If Not IsObject(application) Then Set SapGuiAuto = GetObject("SAPGUI") Set application = SapGuiAuto.GetScriptingEngine End If If Not IsObject(connection) Then Set connection = application.Children(0) End If If Not IsObject(session) Then Set session = connection.Children(0) End If If IsObject(WScript) Then WScript.ConnectObject session, "on" WScript.ConnectObject application, "on" End If session.findById("wnd[0]").maximize

'REM ADDED BY EXCEL *************************************

Dim objExcel Dim objSheet, intRow, i Set objExcel = GetObject(,"Excel.Application") Set objSheet = objExcel.ActiveWorkbook.ActiveSheet For i = 2 to objSheet.UsedRange.Rows.Count COL1 = Trim(CStr(objSheet.Cells(i, 1).Value)) 'Column1

COL2 = Trim(CStr(objSheet.Cells(i, 2).Value)) 'Column2

COL3 = Trim(CStr(objSheet.Cells(i, 3).Value)) 'Column3

COL4 = Trim(CStr(objSheet.Cells(i, 4).Value)) 'Column4

COL5 = Trim(CStr(objSheet.Cells(i, 5).Value)) 'Column5

COL6 = Trim(CStr(objSheet.Cells(i, 6).Value)) 'Column6

'REM ADDED BY EXCEL *************************************

session.findById("wnd[0]/tbar[0]/okcd").text = "/NIP41" session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/usr/cmbRMIPM-MPTYP").key = "PM" session.findById("wnd[0]/usr/cmbRMIPM-MPTYP").setFocus session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/usr/subSUBSCREEN_HEAD:SAPLIWP3:6000/txtRMIPM-WPTXT").text = COL1 session.findById("wnd[0]/usr/subSUBSCREEN_HEAD:SAPLIWP3:6000/txtRMIPM-WPTXT").caretPosition = 9 session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_1:SAPLIWO1:0100/ctxtRIWO1-TPLNR").text = COL2 session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_1:SAPLIWO1:0100/ctxtRIWO1-TPLNR").caretPosition = 5 session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_2:SAPLIWP3:0500/ctxtRMIPM-AUART").text = COL3 session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_2:SAPLIWP3:0500/ctxtRMIPM-AUART").caretPosition = 4 session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/usr/subSUBSCREEN_MPLAN:SAPLIWP3:8001/tabsTABSTRIP_HEAD/tabpT\01/ssubSUBSCREEN_BODY1:SAPLIWP3:8011/subSUBSCREEN_CYCLE:SAPLIWP3:0205/ctxtRMIPM-ZEIEH").text = COL4 session.findById("wnd[0]/usr/subSUBSCREEN_MPLAN:SAPLIWP3:8001/tabsTABSTRIP_HEAD/tabpT\01/ssubSUBSCREEN_BODY1:SAPLIWP3:8011/subSUBSCREEN_CYCLE:SAPLIWP3:0205/ctxtRMIPM-ZEIEH").caretPosition = 3 session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/usr/subSUBSCREEN_MPLAN:SAPLIWP3:8001/tabsTABSTRIP_HEAD/tabpT\01/ssubSUBSCREEN_BODY1:SAPLIWP3:8011/subSUBSCREEN_CYCLE:SAPLIWP3:0205/txtRMIPM-ZYKL1").text = COL5 session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_2:SAPLIWP3:0500/ctxtRMIPM-ILART").text = COL6 session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_2:SAPLIWP3:0500/ctxtRMIPM-ILART").setFocus session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_2:SAPLIWP3:0500/ctxtRMIPM-ILART").caretPosition = 3 session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_2:SAPLIWP3:0500/cmbRMIPM-PRIOK").key = "2" session.findById("wnd[0]/usr/subSUBSCREEN_MITEM:SAPLIWP3:8002/tabsTABSTRIP_ITEM/tabpT\11/ssubSUBSCREEN_BODY2:SAPLIWP3:8022/subSUBSCREEN_ITEM_2:SAPLIWP3:0500/cmbRMIPM-PRIOK").setFocus session.findById("wnd[0]").sendVKey 0 session.findById("wnd[0]/tbar[0]/btn[11]").press session.findById("wnd[1]/usr/radSTART_VALUE_NO").setFocus session.findById("wnd[1]/usr/radSTART_VALUE_NO").select session.findById("wnd[1]/tbar[0]/btn[0]").press session.findById("wnd[0]/tbar[0]/btn[3]").press 'REM FINALIZATION CONTROL CHECK ************************ aux=col1 & " " & col2 & " " & col3 & " " & col4 & " " & col5 & " " & col6 CreateObject("WScript.Shell").run("cmd /c @echo %date% %time% " & aux & " >> C:\Users\Nmiller\AppData\Roaming\SAP\SAP GUI\Scripts\Script3.txt") next msgbox "Process Completed"

'REM FINALIZATION CONTROL CHECK ************************

Add a comment
10|10000 characters needed characters exceeded

Related questions

0 Answers

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.