0

I'm using a SAP GUI Script to make an extraction of a SAP transaction, but the scripts stops because of the save form

Save Form SAP

I have to write the filename and saving path manually, How can i do to let SAP do this automatically?

Code:

Public Sub RunGUIScript_PROJ_WP_INFO_INV()

Dim W_Ret As Boolean
Dim answer As Integer


' Connect to SAP
W_Ret = Attach_Session
If Not W_Ret Then
Exit Sub
End If


On Error GoTo myerr

session.findById("wnd[0]").maximize
session.findById("wnd[0]/usr/txtGD-MAX_LINES").SetFocus
session.findById("wnd[0]/usr/txtGD-MAX_LINES").caretPosition = 7
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[0]/usr/tblSAPLSE16NSELFIELDS_TC/btnPUSH[4,1]").SetFocus
session.findById("wnd[0]/usr/tblSAPLSE16NSELFIELDS_TC/btnPUSH[4,1]").press
session.findById("wnd[1]/tbar[0]/btn[24]").press
session.findById("wnd[1]/tbar[0]/btn[8]").press
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/usr/cntlRESULT_LIST/shellcont/shell").pressToolbarContextButton "&MB_EXPORT"
session.findById("wnd[0]/usr/cntlRESULT_LIST/shellcont/shell").selectContextMenuItem "&XXL"

WaitingForm.Show
MsgBox "Extracción Exitosa", vbInformation, "SAP"

Exit Sub
myerr:
  MsgBox "Error while retrieving data", vbOKOnly + vbCritical

End Sub
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
David Donayo
  • 117
  • 1
  • 12
  • Maqybe [this](https://blogs.sap.com/2014/03/26/new-scripting-option-in-sap-gui-for-windows-730-pl-8/) helps – Storax Aug 10 '20 at 15:30
  • Another way could be this [one](https://stackoverflow.com/questions/58779126/how-to-vba-wait-for-windows-save-dialogbox-and-sendkeys) – Storax Aug 10 '20 at 15:37
  • I activated that option but when I recording the macro, sap didn't record the replacement of the path and filename, idk how to do that. – David Donayo Aug 10 '20 at 15:47
  • I think you need to deactivate the option and then the sapgui recording should give you what you are after. – Storax Aug 10 '20 at 16:40
  • Does this answer your question? [Save PDF from SAP](https://stackoverflow.com/questions/43301299/save-pdf-from-sap) – Suncatcher Aug 11 '20 at 08:56
  • @Storax which option ? – David Donayo Aug 11 '20 at 13:38
  • Option _Show native MS windows dialogs_ should be deactivated. If this does not help you may try the second link I provided. – Storax Aug 11 '20 at 13:57
  • Oh i didn't see it, y put your code before the SaveAs Dialog box but i receive this [error](https://imgur.com/a/Z7uZ9AZ) – David Donayo Aug 11 '20 at 15:00
  • How should I know without knowing the code you are actually using. – Storax Aug 11 '20 at 19:30
  • Before `session.findById("wnd[0]/usr/cntlRESULT_LIST/shellcont/shell").pressToolbarContextButton "&MB_EXPORT"` I added the code of the [post](https://stackoverflow.com/questions/58779126/how-to-vba-wait-for-windows-save-dialogbox-and-sendkeys) you send me. – David Donayo Aug 12 '20 at 12:56

1 Answers1

1

Our SAP recently updated and broke many of my scripts, disabling the "show native MS Windows dialogs" allowed my previous code to run again. A basic SAP script cannot directly inteface with the MS windows dialog box shown in your screen shot.

below is the code to set the path and file name

session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").contextMenu
session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell/shellcont[1]/shell").selectContextMenuItem "&XXL"
session.findById("wnd[1]/tbar[0]/btn[0]").press

'set path and file name
session.findById("wnd[1]/usr/ctxtDY_PATH").text = "\\network\path\to\folder\"
session.findById("wnd[1]/usr/ctxtDY_FILENAME").text = "Filename.xlsx"
session.findById("wnd[1]/tbar[0]/btn[0]").press
SomeGuy
  • 26
  • 3