cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to select path from dropdown list while saving the report in SAP using VBA script?

0 Kudos
512

Hi There, I'm trying to take a export using VBA SAP GUI script and wanted to save a extract in .xlsx format from the List menu bar but it is not letting me save to the desired path.

Below is the code that i wrote as per my logics. Would be great if someone can help me to fix the script as per the requirement.

Sub SAPTCode()

Dim SapGuiAuto, Application, Connection, session As Object, wb As Workbook

Set SapGuiAuto = GetObject("SAPGUI")

Set Application = SapGuiAuto.GetScriptingEngine

Set Connection = Application.Children(0)

Set session = Connection.Children(0)

'Dim Carrid As String

session.FindById("wnd[0]").Maximize

session.FindById("wnd[0]/tbar[0]/okcd").Text = "FBL1N"

session.FindById("wnd[0]").SendVKey 0

session.FindById("wnd[0]/usr/ctxtKD_BUKRS-LOW").Text = " "

session.FindById("wnd[0]/usr/ctxtKD_BUKRS-LOW").SetFocus

session.FindById("wnd[0]/usr/ctxtKD_BUKRS-LOW").CaretPosition = 4

session.FindById("wnd[0]/tbar[1]/btn[8]").Press

session.FindById("wnd[0]/mbar/menu[0]/menu[3]/menu[1]").Select

session.FindById("wnd[0]/tbar[0]/btn[0]").Press

session.FindById("wnd[0]/usr/lbl[36,1]").SetFocus

session.FindById("wnd[0]/usr/lbl[36,1]").CaretPosition = 73

session.FindById("wnd[1]/usr/ctxtDY_SAVEIN/DROPDOWN/DOCUMENTS").Select

session.FindById("wnd[1]/usr/ctxtDY_FILENAME").Text = "Test.xlsx"

session.FindById("wnd[1]/usr/ctxtDY_FILENAME").CaretPosition = 27

session.FindById("wnd[1]/tbar[0]/btn[0]").Press

session.FindById("wnd[0]/tbar[0]/btn[15]").Press

End Sub

Accepted Solutions (0)

Answers (1)

Answers (1)

FrankKrauseGUI
Product and Topic Expert
Product and Topic Expert

Hello Shubham,

the dialog you are showing is a Windows dialog. Such dialogs cannot be used via SAP GUI Scripting - you would need some other automation approach for being able to work with them. Therefore, there is an option in SAP GUI for Windows which lets you replace such dialogs by ABAP dialog boxes (which are not as user friendly, but can be scripted). See the option called "Show native Microsoft Windows Dialogs" here: https://help.sap.com/docs/sap_gui_for_windows/63bd20104af84112973ad59590645513/7ddb7c9c4a4c43219a65e.... This option needs to be deactivated.

Best regards,
Frank