Your code seems buggy and slow for the following reasons:
- intItemsShown is being set, then you use it as a step within a loop and eventually modify it within the loop.
- You have a nested loop that just does a Debug.Print which might slow down your app further
- Since you seem to be traversing a hierarchy of objects, it appears to
me that it would be more appropriate to use recursive calls to
process children, children of children... Parsing SAP output structures might work but is not clean and will probably become a maintenance nightmare in the future.
My recommended alternatives
- Create a RFC that will take your parameters and return the raw data to Excel. This link might me a good start: http://www.vbforums.com/showthread.php?337408-VB-and-SAP-Integration
- Create a web service and call it from Excel VBA
- Create a web page that returns data in HTML that excel can access as a web query. See this link as a start: http://www.techrepublic.com/article/pull-data-into-microsoft-excel-with-web-queries/.
The first option requires ABAP on the SAP side. The two other options assumes that you have a web server integrated with SAP.
For i = 0 To intVerticalScrollEndPoint Step intItemsShown ' <--intItemsShown is being used here
.findById("wnd[0]/usr").VerticalScrollbar.Position = i
intItemsShown = objSession.findById("wnd[0]/usr").Children.Count - 1 ' and modified here
For n = 0 To intItemsShown ' and used here again
Debug.Print .findById("wnd[0]/usr").Children.ElementAt(n).Text
Next n
Next i