VBA - SAP 'Save As' dialogue box

marc81

New Member
Joined
Aug 3, 2017
Messages
16
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
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Thought i'd try a quick bump on this as I am no further with it.

I think the problem is that the Save As dialogue box that comes up is not a SAP box, but a Windows Explorer one. VBA is not even recognising when this box is open so I can't even use SENDKEYS to paste a filename in and save. Any ideas?

Thanks
 
Upvote 0

Forum statistics

Threads
1,216,194
Messages
6,129,449
Members
449,509
Latest member
ajbooisen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top