Link to home
Start Free TrialLog in
Avatar of JJSystems
JJSystems

asked on

Need help scraping information from SAP GUI

I'm trying to pull information from the SAP GUI, and load it into another application. Specifically, I'm trying to get the Vendor Number, Vendor Name, and Invoice Number from the FB60 transaction.  A friend gave me the attached code, but it fails at session.activeWindow.handle with "Object doesn't support this property or method" Any help would be appreciated.
'The following variables are set to define the SAP Client GUI as an object, enable the SAP Scripting Engine, define the SAP Connections, and Sessions to search through for the window title that matches the windowMatchString.
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
Set connection = application.Children(0)
Set session = connection.Children(0)
' Retrieve the window title from the app plan as it runs
windowMatchString = "Enter vendor invoice: Company code 1000"
'The following For Each Statement will cycle through all of the open SAP Client Windows
'and find the window that matches the windowMatchString variable and was last active.
For Each Session in connection.Children
     If session.activeWindow.handle = FindWindow(windowMatchString) Then
      'Pulls the document for the correct window that is active.
      'found the matching session
       set window = session.activeWindow
'
'Define fields accepted from SAP
'Vendor Number
set VendorNumber = application.findById("/app/con[0]/ses[0]/wnd[0]/usr/ctxtINVFO-ACCNT")
'Vendor Name
set VendorName = application.findById("/app/con[0]/ses[0]/wnd[0]/usr/txtADRS-LINE0")
'Invoice Number
set InvoiceNumber = application.findById("/app/con[0]/ses[0]/wnd[0]/usr/txtINVFO-XBLNR")
End If
Next

Open in new window

Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, I really have no idea, but you seem to be using the variable name "Session" for two different things.  Try changing this line:
Set session = connection.Children(0)

to this
Set colSessions = connection.Children(0)

Then change this:
For Each Session in connection.Children

to this
For Each Session in colSessions

Regards,

Rob.
ASKER CERTIFIED SOLUTION
Avatar of JJSystems
JJSystems

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial