Hi Guys, hope someone can help with this.
I am trying to integrate some codes from SAP into a macro, the idea is to export data from SAP (FBL3N) into a excel file, and copy data in that file to another workbook.
Now I have bumped into an error, which is simply because when this macro is running, before it activates the exported file (named as "export"), it turns out hasn't opened yet, then Excel throws a "script out of range" error. I am just wondering is there a way to fix it? I mean I tested it a few days ago it ran smoothly, don't know why it ended up like this again.
I try to set the macro to wait for 5 secs after it clicks "generate", but it doesn't work either. After I click "debug", then the exported file pops up immediately...............
Any thoughts will be appreciated! Thank you guys!
I am trying to integrate some codes from SAP into a macro, the idea is to export data from SAP (FBL3N) into a excel file, and copy data in that file to another workbook.
Now I have bumped into an error, which is simply because when this macro is running, before it activates the exported file (named as "export"), it turns out hasn't opened yet, then Excel throws a "script out of range" error. I am just wondering is there a way to fix it? I mean I tested it a few days ago it ran smoothly, don't know why it ended up like this again.
I try to set the macro to wait for 5 secs after it clicks "generate", but it doesn't work either. After I click "debug", then the exported file pops up immediately...............
Any thoughts will be appreciated! Thank you guys!
VBA Code:
session.findById("wnd[0]").maximize
session.findById("wnd[0]/mbar/menu[0]/menu[3]/menu[1]").Select ---> export to excel file from a general ledger line items page (pops up)
session.findById("wnd[1]/usr/ctxtDY_PATH").Text = "H:\Finance Operations\General\Unidentified Receipts"
session.findById("wnd[1]/usr/ctxtDY_PATH").caretPosition = 93
session.findById("wnd[1]/tbar[0]/btn[11]").press ---> click "replace" existing file (always named as "export")
Application.Wait Now() + TimeValue("0:0:05") ---> ask macro to wait for 5 secs
Workbooks("SAP test.xlsb").Activate
Dim ws2 As Worksheet
Set ws2 = Worksheets("Rawdata 22136")
ws2.Select
Range("A:G").Clear
Workbooks("export.xlsx").Activate ---> error "script out of range" , due to pop-up file "export" not yet open
Worksheets("sheet1").Select
Range("A:G").Copy