I have a VBA code that mixes SAP GUI Scripting and VBA.
Basically I use a SAP transaction and I export it as a Excel sheet, after I click the export button it asks for a place to save.
I have recorded the script using SAP and inserted it into VBA.
The steps are:
- Click the Button to Export (SAP)
(apparently there is no code that involves the "Save As..." window, user must interact)
Click the Button to Go Back to Main Page (SAP)
Set Open Workbook a Name so I can work with it
The problem is that if I run the code it doesn't work. It is like the code doesn't wait until the workbook to open to go further.
I have tried:
- Adding time for the VBA code to wait
- Adding lines (e.g. MsgBox) between the events
session.findById("wnd[0]/mbar/menu[0]/menu[3]/menu[1]").Select '(Step 1)
session.findById("wnd[0]/tbar[0]/btn[3]").press '(Step 2)
session.findById("wnd[0]/tbar[0]/btn[3]").press '(Step 2)
Set Book = ActiveWorkbook '(Step 3)
Set Sheet = ZMMBBook.Worksheets("Sheet1") '(Step 3)
It is expected that the Workbook is set but instead the code runs before it opens. Even trying to add time in between it doesn't work, it is like it only opens after it progresses but when it progresses the workbook is not open so it results in a "Subscript Out of Range" error.
If I insert a breakpoint in the "Set" line the workbook opens and if I proceed the code works normally.
I would want as a solution:
A Way To Insert Lines of Code that make the Code "break" as if in a Breakpoint (but smoothly so end-user can use it)
A way in SAP GUI Scripting to interact with the Save Window (because I'd say it seems that it is what causes the bug)
Any other solution
Thank you, all!