title: SAPGUI Parse GuiUserArea
body: <h2> Problem! </h2>
  <p>Currently at the place that I work We are trying to perform some kind of repetitive task via automatically with the usage of <em>SAPGui</em>, <em>Excel</em> &amp; <em>VBA</em>. 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.</p>
  <h2> Solution! </h2>
  Anyhow I managed to parse these kind of reports depending on certain types of requirements. So, for the first time that I tried to parse any report (shown as GuiUserArea) I've came up with the idea that it would be easy to save the report as unformated text and then go and parse it using VBA (Regexes, Splits, Text Length, ...) instead of using GuiUserArea methods and properties. 
  <p>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 <em>SAPGUI</em> object just to save the files and not to complete more complex tasks as parsing information...</p>
  <p>Working with the GuiUserArea I've came up with the following solution:</p>
  <pre><code>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(&quot;wnd[0]/usr&quot;).HorizontalScrollbar.Position = 10000
          .findById(&quot;wnd[0]/usr&quot;).VerticalScrollbar.Position = 10000
          
          ' Store end points
          intVerticalScrollEndPoint = .findById(&quot;wnd[0]/usr&quot;).VerticalScrollbar.Position
          intHorizontalScrollEndPoint = .findById(&quot;wnd[0]/usr&quot;).HorizontalScrollbar.Position
          
          ' Move to the start of the GuiUserArea
          .findById(&quot;wnd[0]/usr&quot;).HorizontalScrollbar.Position = 0
          .findById(&quot;wnd[0]/usr&quot;).VerticalScrollbar.Position = 0
          
          ' Items per page being shown
          intItemsShown = objSession.findById(&quot;wnd[0]/usr&quot;).Children.Count - 1
          
          Dim i As Integer
          Dim n As Integer
          
          For i = 0 To intVerticalScrollEndPoint Step intItemsShown
              .findById(&quot;wnd[0]/usr&quot;).VerticalScrollbar.Position = i
              intItemsShown = objSession.findById(&quot;wnd[0]/usr&quot;).Children.Count - 1
              For n = 0 To intItemsShown
                  Debug.Print .findById(&quot;wnd[0]/usr&quot;).Children.ElementAt(n).Text
              Next n
          Next i
          
      End With
  End Sub
                
  </code></pre>
  <p>The code shown above works <em>perfectly</em> except for the following statements:</p>
  <ul>
  <li><p>It almost parses all kind of <em>GuiUserArea</em> 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 <em>SAPGUI</em> object.</p>
  </li>
  <li><p>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 <em>.NET</em> and <em>SAPGUI</em> object with no sucess in order to speed up the process.</p>
  </li>
  </ul>
  <p>But at the end of the road, it seems that <em>SAPGUI</em> object was not designed for these kind of tasks.</p>
  <h2> Questions! </h2>
  <ul>
  <li>Do you have any other method to try to parse GuiUserArea?</li>
  <li>Have you tried to use a high level programming language (or even a scripting language)  in order to interact with SAP system instead of VBA?</li>
  <li>Do you know if there is any other way to interact with SAP system rather than <em>SAPGUI</em> Object  (Have you tried SAP .NET Connector?)</li>
  </ul>