0

I have recorded an script which makes the Save As dialog pops up, in transaction code FBL5N.

However I cannot use any command such as sendkey.

I need a code to provide a file path and file name.

so far I have the below code: (coming from SAP script recording and playback)

If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = application.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]/usr/lbl[30,2]").setFocus
session.findById("wnd[0]/usr/lbl[30,2]").caretPosition = 25
session.findById("wnd[0]").sendVKey 16

Thank you.

David

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48

2 Answers2

1

Please see my post "Save PDF from SAP" where I posted a solution to handle a Save as Window. If works for SAP and other windows as well because it is based on WinAPI.

Basically, you have 4 steps to follow:

  1. transform a vbs script into VBA (that you will run in excel). Do not include the line that triggers the save as window. Start with:

    Sub script() Dim SapAPP As Variant Dim i As Integer Set SapGuiAuto = GetObject("SAPGUI") Set SapAPP = SapGuiAuto.GetScriptingEngine Set Connection = SapAPP.Children(0) Set Session = Connection.Children(0)

2.create a new script ONLY with the line that triggers the Save as window. For example:

If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = application.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]").sendVKey 16

3.Ask VBA to run this VB Script

Shell "wscript insert_path_here", vbNormalFocus

4.Handle the Save as Window (as described in my post).

This worked for me in a different SAP menu, but FBL5n should be exactly the same.

Best,

OGERWOLF
  • 117
  • 4
  • 13
0

I'm not sure how tcode FBL5N works but i use this code to export the results on some basis transactions. It might work for your case please try it.

session.findById("wnd[0]/mbar/menu[0]/menu[1]/menu[2]").select
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/ctxtDY_PATH").text = "C:\folder1\folder2"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "filename.txt"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 13
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 2
session.findById("wnd[1]/tbar[0]/btn[11]").press
session.findById("wnd[0]/tbar[0]/btn[3]").press