Skip to Content
0
Nov 05, 2019 at 09:24 AM

Export report from SM37 and save to specified drive

113 Views

Hello All, I would like to check with you how to export the report from SM37 and save it in specified drive. I have tried the script from scriptman but unsuccessful. Sub export()
   
    EXCEL_Path = "\\C:\Users\beeshlim\Desktop\DMA"
    myWorkbook = test88 & ".txt"
    
If Not IsObject(SAPApp) Then
       Set SAPGUIAuto = GetObject("SAPGUI")
       Set SAPApp = SAPGUIAuto.GetScriptingEngine
    End If
    
    If Not IsObject(Connection) Then
        Set Connection = SAPApp.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 = "/nsm37"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtBTCH2170-FROM_DATE").Text = "03.11.2019"
session.findById("wnd[0]/usr/ctxtBTCH2170-TO_DATE").Text = "04.11.2019"
session.findById("wnd[0]/usr/ctxtBTCH2170-TO_DATE").SetFocus
session.findById("wnd[0]/usr/ctxtBTCH2170-TO_DATE").caretPosition = 10
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/usr/chk[1,12]").Selected = True
'session.findById("wnd[0]/usr/chk[1,13]").SetFocus
session.findById("wnd[0]/tbar[1]/btn[44]").press
session.findById("wnd[0]/usr/lbl[14,3]").SetFocus
session.findById("wnd[0]/usr/lbl[14,3]").caretPosition = 0
session.findById("wnd[0]").sendVKey 2
session.findById("wnd[0]/tbar[1]/btn[46]").press
session.findById("wnd[1]/usr/txtDIS_TO").Text = "50"
session.findById("wnd[1]/usr/txtDIS_TO").SetFocus
session.findById("wnd[1]/usr/txtDIS_TO").caretPosition = 2
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/mbar/menu[5]/menu[5]/menu[2]/menu[2]").Select
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/ctxtDY_PATH").Text = EXCEL_Path
session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = myWorkbook
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 6
session.findById("wnd[1]/tbar[0]/btn[11]").press
End Sub