Skip to Content
avatar image
Former Member

how to get data from mm03 to excel


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]/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]").caretPosition = 0


session.findById("wnd[1]/usr/ctxtRMMG1-WERKS").text = "plant"


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,



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

fir.jpg (70.7 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Dec 30, 2015 at 08:25 AM

    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, 


    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 31, 2015 at 07:45 AM


    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]").caretPosition = 0

    for ex

    for k=0 to 1


    session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW/txtMSICHTAUSW-DYTXT[0,k]").caretPosition = 0

    but it didnt work ,

    please help me with this.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member
      Dim K as long
      For K = 0 to 1
           session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW/txtMSICHTAUSW-DYTXT[0," & k &"]").setFocus Next K

      You have included your variable K inside the quotation marks which marks it as Text

      use the & symbol to conjugate the line as above


  • avatar image
    Former Member
    Dec 31, 2015 at 12:24 PM

    thanks Robin Wilkinson for your kind gesture,

    you saved the day.


    Add comment
    10|10000 characters needed characters exceeded