Hi All,
I'm new to the forum and pretty new to VBA so be easy with me
I'm currently trying to write a script that will run a transaction in SAP, and download the output to a specific location. There are 2 ways to download the output, one through the menu structure in SAP which I can code as SAP records the macro, but the one I need involves clicking on a 'download to excel' button that in turn opens up a 'save as' box, for some reason SAP doesn't record this action as a macro. I can get VBA to get to the point of opening up the dialogue box but I can't get it to fill in the filename and then hit save. Any advice? My current script is below;
------------------------------------------------------------------------
Sub SAPTest()
If Not IsObject(App) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set App = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = App.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 App, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "ZL18"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtS_SHIPP").Text = ThisWorkbook.Sheets("Sheet1").Range("C4").Value
session.findById("wnd[0]/usr/ctxtS_DDAT").Text = ThisWorkbook.Sheets("Sheet1").Range("D2").Value
session.findById("wnd[0]/usr/ctxtS_ROUTE-LOW").SetFocus
session.findById("wnd[0]/usr/ctxtS_ROUTE-LOW").caretPosition = 0
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[34]").press
End Sub
------------------------------------------------------------------------
Any help much appreciated.
Marc
I'm new to the forum and pretty new to VBA so be easy with me
I'm currently trying to write a script that will run a transaction in SAP, and download the output to a specific location. There are 2 ways to download the output, one through the menu structure in SAP which I can code as SAP records the macro, but the one I need involves clicking on a 'download to excel' button that in turn opens up a 'save as' box, for some reason SAP doesn't record this action as a macro. I can get VBA to get to the point of opening up the dialogue box but I can't get it to fill in the filename and then hit save. Any advice? My current script is below;
------------------------------------------------------------------------
Sub SAPTest()
If Not IsObject(App) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set App = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = App.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 App, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "ZL18"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtS_SHIPP").Text = ThisWorkbook.Sheets("Sheet1").Range("C4").Value
session.findById("wnd[0]/usr/ctxtS_DDAT").Text = ThisWorkbook.Sheets("Sheet1").Range("D2").Value
session.findById("wnd[0]/usr/ctxtS_ROUTE-LOW").SetFocus
session.findById("wnd[0]/usr/ctxtS_ROUTE-LOW").caretPosition = 0
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[34]").press
End Sub
------------------------------------------------------------------------
Any help much appreciated.
Marc