VBA - SAP 'Save As' dialogue box

marc81

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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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