通过EXCEL宏和SAPScript进行批量业务处理SAP提供了很多批量导入的工具,但问题是一般情况下不会赋予普通用户这些权限,因此我结合EXCELVBA和SAPScript功能整理出一个简易的批量业务处理方式,供大家参考使用SAPScriptRecording功能录制SAP操作,生成代码块1.激活SAPScriptRecording2.选择存放路径和script代码块文件名称3.点击开始录制SAP操作,建议以”/N”+事务代码,以保存为结尾。生成如下程序代码文件,可以用文本编辑器打开通过EXCELVBA编写宏代码,用于读取数据模板和导入SAP1.进入VBA编辑视图2.复制Script代码块中的代码,并做以下适当修改:a)在两个Application和Connection之前加入SAPb)修改录制中的固定值,改为模板中的相应字段,如Range(A&I).Value等c)如有更为复杂的数据处理需求,可以在宏代码中加入适当的判断或者循环语句以下代码用于修改物料主数据的,前段和末端代码可以沿用,只需用script代码覆盖病修改中段原代码即可。供参考。SubEXCEL_to_SAP()yes_No=MsgBox(DoyouwanttouploaddataintoSAPreally?,vbOKCancel)Ifyes_No=2ThenEndEndIfRange(Z1).Value==COUNTA(A:A):TEMP=Range(Z1).Value:Range(Z1).Value=OnErrorGoToNotLoggedOnSAP:SetSapGuiAuto=GetObject(SAPGUI)'GettheSAPGUIScriptingobjectSetSapApplication=SapGuiAuto.GetScriptingEngine'GetthecurrentlyrunningSAPGUISetSapConnection=SapApplication.Children(0)'GetthefirstsystemthatiscurrentlyconnectedSetsession=SapConnection.Children(0)'Getthefirstsession(window)onthatconnectionGoTo10:NotLoggedOnSAP:x=MsgBox(YouarenotloggedonSAP.Pleaselogonandtryagain.,vbOKOnly,NotLoggedonSAP)ExitSubOnErrorGoTo010IfTEMP1ThenForI=2ToTEMP'**********************1.copyfromscrip'**********************2.addSAPbefore2Applicationand2Connectioninnext10lines'**********************3.changefixedvaluebyfields'value,referto-Range(A&I).Value-IfNotIsObject(Application)ThenSetSapGuiAuto=GetObject(SAPGUI)SetSapApplication=SapGuiAuto.GetScriptingEngineEndIfIfNotIsObject(Connection)ThenSetSapConnection=SapApplication.Children(0)EndIfIfNotIsObject(session)ThenSetsession=SapConnection.Children(0)EndIfIfIsObject(WScript)ThenWScript.ConnectObjectsession,onWScript.ConnectObjectApplication,onEndIfsession.findById(wnd[0]).maximizesession.findById(wnd[0]/tbar[0]/okcd).Text=/nmm02session.findById(wnd[0]).sendVKey0session.findById(wnd[0]/usr/ctxtRMMG1-MATNR).Text=Range(A&I).Valuesession.findById(wnd[0]/usr/ctxtRMMG1-MATNR).caretPosition=12session.findById(wnd[0]).sendVKey0session.findById(wnd[1]).sendVKey0session.findById(wnd[0]/usr/tabsTABSPR1/tabpSP01/ssubTABFRA1:SAPLMGMM:2004/subSUB2:SAPLMGD1:2001/ctxtMARA-EXTWG).Text=Range(B&I).Valuesession.findById(wnd[0]/usr/tabsTABSPR1/tabpSP01/ssubTABFRA1:SAPLMGMM:2004/subSUB2:SAPLMGD1:2001/ctxtMARA-EXTWG).SetFocussession.findById(wnd[0]/usr/tabsTABSPR1/tabpSP01/ssubTABFRA1:SAPLMGMM:2004/subSUB2:SAPLMGD1:2001/ctxtMARA-EXTWG).caretPosition=1session.findById(wnd[0]/tbar[0]/btn[11]).presssession.findById(wnd[0]).sendVKey0'**********************copyfromscrip-NextEndIfEndSub