SAP relate VBA - Export Data Waiting Time

Koala123

New Member
Joined
Apr 13, 2019
Messages
24
Office Version
  1. 365
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!

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
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,215,674
Messages
6,126,144
Members
449,294
Latest member
Jitesh_Sharma

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top