SAPGUI Parse GuiUserArea
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
First of all, thanks for posting your question. Your efforts on trying to solve your problem is helping me with mine.
Just found out some information that might help you to handle the horizontal and the vertical scroll bars
In my case, i'm working with a PFCGGuiUserArea which is an object of GuiUserArea Class. This class, as you pointed out in you example, has this two parameters, the HorizontalScrollbar and the VerticalScrollbar. From these two parameters (they were created based on a class), you have also the minimum, maximum and pagesize parameters.
In the case of the Vertical:
VerticalScrollbar Maximum: 349 '==> Total Rows of the GuiUserArea
VerticalScrollbar Minimum: 0 '==> First Row of the GuiUserArea
VerticalScrollbar Position: 1 '==> Position of the Cursor
VerticalScrollbar Page Size: 34 '==> Total Rows per Page
In the case of the horizontal
HorizontalScrollbar Maximum: 190 '==> Total of Columns available
HorizontalScrollbar Minimum: 0 '==> First Column Available
HorizontalScrollbar Position: 0 '==> Position of the cursor
HorizontalScrollbar Page Size: 255 '==> Total Columns per Page
So, you could improve your code pointing to this properties in order to solve the wide horizontal scrolls. This will get the exact information from the system, so you don't have to pass 1000 to the position.
Best Regards, Caio