Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

As Holger Kohn stated here, file dialogues are GUI-modal and recordable in SAP-Basis Release 740 only. Meaning, if you're up to date, you won't have troubles to control Save-As or Open-dialogues within your scripts. But also for those of us still on earlier releases, there's no need to despair!

This is how you get it done:

The key to accessing external file dialogues while executing your SAPGui Script, is Windows API functions. Basically, it's about finding the right window and bringing it to the foreground, so you can manipulate it via sendkey commands. It's first of all these two functions which you have to make use of:


Public Declare Function FindWindow Lib "user32" _


          (ByVal lpClassName As String, ByVal lpWindowName As String) As Long



Private Declare Function SetForegroundWindow Lib "user32" _


         (ByVal hwnd As Long) As Long


If you can't find out the ipClassName (e.g. using tools like Spy++) and the FindWindow function won't find and return the window handle only by it's name, don't worry. There is a ready-to-use solution that's more complex but also more reliable: Access/VBA Tutorials - Bring an external application window to the foreground. (You can simply copy and paste it ...)

But be careful: If you refer to Gui-object methods (e.g. .pressToolbarButton "XYZ") to open the file-dialogue, your mission is already bound to fail: That's because your client has to wait for the server to answer until it can proceed. Meaning, the code that follows (bringing the save-dialogue to the foreground, sendkeys etc...) will have to wait in the queue.

That's why I am using sendkeys not only to fill-in and confirm the file-dialogue, but already to open it. This is how I got it solved, hope it will help some of you, too....









' ----------------------- Import Document -------------------------

  









Session.findById("wnd[0]/shellcont[0]/shell/shellcont[1]/shell").doubleClickItem "Key11", "Column1"

















Call PressButton("Dokument importieren")         ' Finding the button turned out tricky for me, so I put it into a separate procedure, for better readability...
Application.Wait (Now + TimeSerial(0, 0, 3))      ' This pause makes sure the window is already open when you look for it....









bln = FnSetForegroundWindow("Öffnen")

  













SendKeys ThisWorkbook.Path & "\testmail.msg", True
SendKeys "{ENTER}", True

  









Application.Wait (Now + TimeSerial(0, 0, 1))

  

















Session.findById("wnd[1]/usr/cmb/WSV/CA_DOC_IMPORT-LOB").Key = "ACC"
Session.findById("wnd[1]/usr/ctxt/WSV/CA_DOC_IMPORT-DOCCLASS").Text = "YOTH"
Session.findById("wnd[1]/usr/cmb/WSV/CA_DOC_IMPORT-VISIBILITY_LEVEL").Key = "D"

  


2 Comments