on 08-18-2014 7:00 PM
Hi experts,
I need help. I make the script for report to SAP with Excel.
In the MM03, has the position of stock of my deposits. But if the material was no created position for him, we have a error. How to make ?
The code:
Thanks
Sub run()
If Not IsObject(AppSapGui) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set AppSapGui = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = AppSapGui.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 AppSapGui, "on"
End If
session.findById("wnd[0]").maximize
For x = 5 To 5000
If Cells(x, 1) = "" Then Exit For
session.findById("wnd[0]/tbar[0]/okcd").Text = "/NMM03"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").Text = Cells(x, 1)
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/ctxtRMMG1-WERKS").Text = "7351"
session.findById("wnd[1]/usr/ctxtRMMG1-LGORT").Text = Cells(x, 4) 'dep
session.findById("wnd[1]/usr/ctxtRMMG1-LGORT").SetFocus
session.findById("wnd[1]/usr/ctxtRMMG1-LGORT").caretPosition = 4
session.findById("wnd[1]/tbar[0]/btn[0]").press
Cells(x, 2) = session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP20/ssubTABFRA1:SAPLMGMM:2000/subSUB1:SAPLMGD1:1005/txtMAKT-MAKTX").Text
session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP20/ssubTABFRA1:SAPLMGMM:2000/subSUB1:SAPLMGD1:1005/txtMAKT-MAKTX").caretPosition = 10
Cells(x, 5) = session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP20/ssubTABFRA1:SAPLMGMM:2000/subSUB2:SAPLMGD1:2701/txtMARD-LGPBE").Text 'postiotn
session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP20/ssubTABFRA1:SAPLMGMM:2000/subSUB2:SAPLMGD1:2701/txtMARD-LGPBE").caretPosition = 3
session.findById("wnd[0]").sendVKey 0
Cells(x, 3) = session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP30/ssubTABFRA1:SAPLMGMM:2000/subSUB3:SAPLMGD1:3002/txtMARD-LABST").Text
session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP30/ssubTABFRA1:SAPLMGMM:2000/subSUB3:SAPLMGD1:3002/txtMARD-LABST").caretPosition = 12
session.findById("wnd[0]/tbar[0]/btn[3]").press
Next
End Sub
Hello.
Check if statusbar messagetype is <> "Error":
Sub run()
If Not IsObject(AppSapGui) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set AppSapGui = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = AppSapGui.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 AppSapGui, "on"
End If
Session.FindById("wnd[0]").maximize
For x = 5 To 5000
If Cells(x, 1) = "" Then Exit For
Session.FindById("wnd[0]/tbar[0]/okcd").Text = "/nMM03"
Session.FindById("wnd[0]").sendVKey 0
Session.FindById("wnd[0]/usr/ctxtRMMG1-MATNR").Text = Cells(x, 1)
Session.FindById("wnd[0]").sendVKey 0
Session.FindById("wnd[1]/tbar[0]/btn[0]").press
Session.FindById("wnd[1]/usr/ctxtRMMG1-WERKS").Text = "7351"
Session.FindById("wnd[1]/usr/ctxtRMMG1-LGORT").Text = Cells(x, 4) 'dep
Session.FindById("wnd[1]/tbar[0]/btn[0]").press
If Session.FindById("wnd[0]/sbar").MessageType <> "E" Then
Cells(x, 2) = Session.FindById("wnd[0]/usr/tabsTABSPR1/tabpSP20/ssubTABFRA1:SAPLMGMM:2000/subSUB1:SAPLMGD1:1005/txtMAKT-MAKTX").Text
Cells(x, 5) = Session.FindById("wnd[0]/usr/tabsTABSPR1/tabpSP20/ssubTABFRA1:SAPLMGMM:2000/subSUB2:SAPLMGD1:2701/txtMARD-LGPBE").Text 'position
Session.FindById("wnd[0]").sendVKey 0
Cells(x, 3) = Session.FindById("wnd[0]/usr/tabsTABSPR1/tabpSP30/ssubTABFRA1:SAPLMGMM:2000/subSUB3:SAPLMGD1:3002/txtMARD-LABST").Text
Session.FindById("wnd[0]/tbar[0]/btn[3]").press
End If
Next
End Sub
Hope this help you.
Best regards,
Holger
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.