SAP macro using VB script -
i wan mass upload of data in sap, update price on 100 po's. can write macro using vb script , run through sap script recording , playback option. while doing teh macro gets stuck sap gui id gets changed time time. there fix this.
example code:
if not isobject(application) set sapguiauto = getobject("sapgui") set application = sapguiauto.getscriptingengine end if if not isobject(connection) set connection = application.children(0) end if if not isobject(session) set session = connection.children(0) end if if isobject(wscript) wscript.connectobject session, "on" wscript.connectobject application, "on" end if session.findbyid("wnd[0]").maximize session.findbyid("wnd[0]/tbar[0]/okcd").text = "me22n" session.findbyid("wnd[0]").sendvkey 0 session.findbyid("wnd[0]/tbar[1]/btn[17]").press session.findbyid("wnd[1]/usr/subsub0:saplmegui:0003/ctxtmepo_select-ebeln").text = "44101194" session.findbyid("wnd[1]/usr/subsub0:saplmegui:0003/ctxtmepo_select-ebeln").caretposition = 8 session.findbyid("wnd[1]").sendvkey 0 session.findbyid("wnd[0]/usr/subsub0:saplmegui:0015/subsub2:saplmeviews:1100/subsub2:saplmeviews:1200/subsub1:saplmegui:1211/tblsaplmeguitc_1211/ctxtmepo1211-konnr[17,0]").text = "46062154" session.findbyid("wnd[0]/usr/subsub0:saplmegui:0015/subsub2:saplmeviews:1100/subsub2:saplmeviews:1200/subsub1:saplmegui:1211/tblsaplmeguitc_1211/txtmepo1211-ktpnr[18,0]").text = "10" session.findbyid("wnd[0]/usr/subsub0:saplmegui:0015/subsub2:saplmeviews:1100/subsub2:saplmeviews:1200/subsub1:saplmegui:1211/tblsaplmeguitc_1211/txtmepo1211-ktpnr[18,0]").setfocus session.findbyid("wnd[0]/usr/subsub0:saplmegui:0015/subsub2:saplmeviews:1100/subsub2:saplmeviews:1200/subsub1:saplmegui:1211/tblsaplmeguitc_1211/txtmepo1211-ktpnr[18,0]").caretposition = 3 = 0 3 session.findbyid("wnd[0]").sendvkey 0 next session.findbyid("wnd[0]/usr/subsub0:saplmegui:0015/subsub2:saplmeviews:1100/subsub2:saplmeviews:1200/subsub1:saplmegui:1211/tblsaplmeguitc_1211/txtmepo1211-netpr[9,0]").text = "29.4" session.findbyid("wnd[0]/usr/subsub0:saplmegui:0015/subsub2:saplmeviews:1100/subsub2:saplmeviews:1200/subsub1:saplmegui:1211/tblsaplmeguitc_1211/txtmepo1211-netpr[9,0]").setfocus session.findbyid("wnd[0]/usr/subsub0:saplmegui:0015/subsub2:saplmeviews:1100/subsub2:saplmeviews:1200/subsub1:saplmegui:1211/tblsaplmeguitc_1211/txtmepo1211-netpr[9,0]").caretposition = 14 session.findbyid("wnd[0]").sendvkey 0 on error resume next session.findbyid("wnd[0]/tbar[1]/btn[21]").press = 0 3 session.findbyid("wnd[0]/tbar[1]/btn[18]").press session.findbyid("wnd[1]/tbar[0]/btn[0]").press next session.findbyid("wnd[0]/tbar[0]/btn[11]").press session.findbyid("wnd[0]/tbar[1]/btn[17]").press session.findbyid("wnd[1]/usr/subsub0:saplmegui:0003/ctxtmepo_select-ebeln").text = "44101195" session.findbyid("wnd[1]/usr/subsub0:saplmegui:0003/ctxtmepo_select-ebeln").caretposition = 8 session.findbyid("wnd[1]").sendvkey 0 session.findbyid("wnd[0]/usr/subsub0:saplmegui:0015/subsub2:saplmeviews:1100/subsub2:saplmeviews:1200/subsub1:saplmegui:1211/tblsaplmeguitc_1211/ctxtmepo1211-konnr[17,0]").text = "46062154" session.findbyid("wnd[0]/usr/subsub0:saplmegui:0015/subsub2:saplmeviews:1100/subsub2:saplmeviews:1200/subsub1:saplmegui:1211/tblsaplmeguitc_1211/txtmepo1211-ktpnr[18,0]").text = "10" session.findbyid("wnd[0]/usr/subsub0:saplmegui:0015/subsub2:saplmeviews:1100/subsub2:saplmeviews:1200/subsub1:saplmegui:1211/tblsaplmeguitc_1211/txtmepo1211-ktpnr[18,0]").setfocus session.findbyid("wnd[0]/usr/subsub0:saplmegui:0015/subsub2:saplmeviews:1100/subsub2:saplmeviews:1200/subsub1:saplmegui:1211/tblsaplmeguitc_1211/txtmepo1211-ktpnr[18,0]").caretposition = 3 = 0 3 session.findbyid("wnd[0]").sendvkey 0 next session.findbyid("wnd[0]/usr/subsub0:saplmegui:0015/subsub2:saplmeviews:1100/subsub2:saplmeviews:1200/subsub1:saplmegui:1211/tblsaplmeguitc_1211/txtmepo1211-netpr[9,0]").text = "29.4" session.findbyid("wnd[0]/usr/subsub0:saplmegui:0015/subsub2:saplmeviews:1100/subsub2:saplmeviews:1200/subsub1:saplmegui:1211/tblsaplmeguitc_1211/txtmepo1211-netpr[9,0]").setfocus session.findbyid("wnd[0]/usr/subsub0:saplmegui:0015/subsub2:saplmeviews:1100/subsub2:saplmeviews:1200/subsub1:saplmegui:1211/tblsaplmeguitc_1211/txtmepo1211-netpr[9,0]").caretposition = 14 session.findbyid("wnd[0]").sendvkey 0
do use spesific transaction? way delete part until maximize @ first. , put this
set sapguiauto = getobject("sapgui") set sapapp = sapguiauto.getscriptingengine set sapcon = sapapp.children(0) set session = sapcon.children(0)
Comments
Post a Comment