on 12-23-2015 8:37 AM
hi,
I would like to get data from mm03 transaction, i used vb coding to get details, below is the sap scripting of it.
I used F1 in the mm03 transaction to get field name, i have attached the image,
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
session.findById("wnd[0]/tbar[0]/okcd").text = "mm03"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").text = "partnumber"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW").verticalScrollbar.position = 21
session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW").verticalScrollbar.position = 18
session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW").getAbsoluteRow(20).selected = true
session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW/txtMSICHTAUSW-DYTXT[0,2]").setFocus
session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW/txtMSICHTAUSW-DYTXT[0,2]").caretPosition = 0
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/ctxtRMMG1-WERKS").text = "plant"
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/tabsTABSPR1/tabpSP27/ssubTABFRA1:SAPLMGMM:2000/subSUB1:SAPLMGD1:1009/ctxtRMMG1-MATNR").caretPosition = 8
i got some details like if u want details from a menu u have to use the field name to extract text,
like
cells(1,1).value=session.findById("wnd[0]/usr/fieldname).text
but i couldnt make it to happend,
my vb code is
Cells(1, 6).Value = .findById("wnd[0]/usr/ctxtRMMG1-MATNR").Text
Cells(1, 5).Value = .findById("wnd[0]/usr/tabsTABSPR1/tabpSP27/ssubTABFRA1:SAPLMGMM:2000/subSUB1:SAPLMGD1:1009/ctxtRMMG1-MATNR").Text
will need some more information i'm afraid
couple of quick checks first
Have you declared the sap object as a window VBA
Sub Get_Info()
Dim SapGuiAuto As Object
Dim SapApp As Object
Dim SAPCon As Object
Dim Session As Object
Set SapGuiAuto = GetObject("SAPGUI") 'Get the SAP GUI Scripting object
Set SapApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
Set SAPCon = SapApp.Children(SapApp.Children.Count - 1) 'Get the first system that is currently connected
Set Session = SapApp.Children(SapApp.Children.Count - 1).sessions(SapApp.Children(SapApp.Children.Count - 1).sessions.Count - 1)
'Get the first session (window) on that connection
' Sap Recorded Script goes here to get you to the right screen
'Write Data to Excel
sheet1.cells(1,1) = session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").Text
End sub
Preferably use fuller referencing for the cell output like worksheets("sheet 1").cells(1,2) = "Some Item" or Sheet1.cells(1,2) = "Some Item" instead of cell(6,1) = "Text"
Without your error or seeing your full code i can only guess,
essentially once you get the binding of the sap session to the Session Object in your VBA code you can use the Watch Window to explore and find the items you want,
Robin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks Robin Wilkinson for your kind gesture,
you saved the day.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
i want to run a loop on this i dont know how to make it dynamic. i need some help i tried looping as
session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW/txtMSICHTAUSW-DYTXT[0,2]").setFocus
session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW/txtMSICHTAUSW-DYTXT[0,2]").caretPosition = 0
for ex
for k=0 to 1
session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW/txtMSICHTAUSW-DYTXT[0,k]").setFocus
session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW/txtMSICHTAUSW-DYTXT[0,k]").caretPosition = 0
but it didnt work ,
please help me with this.
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.