0

I have recorded one SAP scripting and am using the script in my VBA code to run. My issue is one dialog box coming on clicking on the report generate window is not getting captured through SAP script recording .Rest all steps are getting recorded through SAP and I have used these script in VBA. as shown below :

  Sub sap_scripting()

   Set SAPGuiAuto = GetObject("SAPGUI")

    Set ObjGui = SAPGuiAuto.GetScriptingEngine

    Set ObjConn = ObjGui.Children(0)

   Set session = ObjConn.Children(0)
  'below SAP script recorded steps
  session.findById("wnd[0]").maximize
  session.findById("wnd[0]/tbar[0]/okcd").Text = "Tcode"

  --------------------------------
  --------------------------------
  session.findById("wnd[1]/tbar[0]/btn[0]").press  '*This opens new dialog window for file explorer 

 'from here I lost the control on VBA code 

   '  I am trying to capture window through may manual vba code but this is not getting 
    executed as the dialogue box window is  waiting for some action. 
 Set WshShell = CreateObject("WScript.Shell")

  
      ret = WshShell.AppActivate("Save As")

  Loop Until ret = True

  
  ret = WshShell.AppActivate("Save As")

   If ret = True Then

     ret = WshShell.AppActivate("Save As")

     WshShell.SendKeys "{TAB}"
     WshShell.SendKeys "{TAB}"
     WshShell.SendKeys "{TAB}"
     WshShell.SendKeys "{TAB}"
     WshShell.SendKeys "{TAB}"
     WshShell.SendKeys "{TAB}"
     WshShell.SendKeys "newfilename"
     WshShell.SendKeys "{TAB}"
     WshShell.SendKeys "{TAB}"
     WshShell.SendKeys "{ENTER}"


    End If

I am trying to select the folder from Save As file dialogue box and give the file name through VBA. Please help me how to fix issue.First issue is VBA is losing control when Dialogue box appears.Second how to select the folder and give file name

enter image description here

FaisalThayyil
  • 85
  • 1
  • 3
  • 14
  • I would suggest you to use Spy++, or similar to find the respective (SaveAs) window handle (by its title and class), see its children tree and using API (`findWindow`, `FindWindowEx` and `SendMessage`) you can control it to consistently do what you need. `Sendkeys` is not reliable when moving the cursor, anyhow... – FaneDuru Aug 14 '23 at 09:42
  • Any good link to learn Spy++ – FaisalThayyil Aug 14 '23 at 11:12
  • Does this answer your question? [How to automatically set path and filename of sap .xlsx/.xls/.xlsm extraction with SAP GUI](https://stackoverflow.com/questions/63343122/how-to-automatically-set-path-and-filename-of-sap-xlsx-xls-xlsm-extraction-wi) – Sandra Rossi Aug 14 '23 at 11:31
  • Another solution, more code: [How to make VBA script automate a "Save As" window](https://stackoverflow.com/questions/43301299/how-to-make-vba-script-automate-a-save-as-window) – Sandra Rossi Aug 14 '23 at 11:32
  • Depending on your SAPGUI version [this](https://blogs.sap.com/2014/03/26/new-scripting-option-in-sap-gui-for-windows-730-pl-8/) might help – Storax Aug 14 '23 at 13:47
  • https://stackoverflow.com/a/58779515/6600940 – Storax Aug 14 '23 at 13:56

0 Answers0