Currently at the place that I work We are trying to perform some kind of repetitive task via automatically with the usage of SAPGui, Excel & VBA. Usually, the most of the reports that We gather from SAP's TCodes are being displayed with a GuiUserArea which is not easy, neat and quick to parse.
Please note that using this procedure (Saving the files) is more easy and quick to parse the information, But what would be the point of using the SAPGUI object just to save the files and not to complete more complex tasks as parsing information...
Working with the GuiUserArea I've came up with the following solution:
Sub ParseSAPGUI()
Dim objSAPGui As Object
Dim objApplication As Object
Dim objConnection As Object
Dim objSession As Object
If (objSAPGui Is Nothing) Then
Set objSAPGui = GetSAPGuiObject()
Set objApplication = GetSAPGuiScriptEngine(objSAPGui)
End If
If (objConnection Is Nothing) Then
Set objConnection = GetSAPGuiConnection(objApplication)
End If
If (objSession Is Nothing) Then
Set objSession = GetSAPGuiSession(objConnection)
End If
With objSession
Dim intItemsShown As Integer
Dim intVerticalScrollEndPoint As Integer
Dim intHorizontalScrollEndPoint As Integer
' Move to the end of the GuiUserArea
.findById("wnd[0]/usr").HorizontalScrollbar.Position = 10000
.findById("wnd[0]/usr").VerticalScrollbar.Position = 10000
' Store end points
intVerticalScrollEndPoint = .findById("wnd[0]/usr").VerticalScrollbar.Position
intHorizontalScrollEndPoint = .findById("wnd[0]/usr").HorizontalScrollbar.Position
' Move to the start of the GuiUserArea
.findById("wnd[0]/usr").HorizontalScrollbar.Position = 0
.findById("wnd[0]/usr").VerticalScrollbar.Position = 0
' Items per page being shown
intItemsShown = objSession.findById("wnd[0]/usr").Children.Count - 1
Dim i As Integer
Dim n As Integer
For i = 0 To intVerticalScrollEndPoint Step intItemsShown
.findById("wnd[0]/usr").VerticalScrollbar.Position = i
intItemsShown = objSession.findById("wnd[0]/usr").Children.Count - 1
For n = 0 To intItemsShown
Debug.Print .findById("wnd[0]/usr").Children.ElementAt(n).Text
Next n
Next i
End With
End Sub
The code shown above works perfectly except for the following statements:
It almost parses all kind of GuiUserArea reports, except for the ones with a wide horizontal window. I am working to fix these issue but there is a lack of documentation for the SAPGUI object.
Slow and very slow for a big amount of data (As it is supposed to be, since We are using VBA to COM Objects). Tried to work with .NET and SAPGUI object with no sucess in order to speed up the process.
But at the end of the road, it seems that SAPGUI object was not designed for these kind of tasks.
Your code seems buggy and slow for the following reasons:
My recommended alternatives
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With