on 05-23-2013 7:57 PM
Hello,
at work we often have to transfer customerdata from SAP GUI to Outlook 2003.
At the moment we have to get the data manually via copy and paste from SAP GUI Textfields.
In the long term this is very frustrating and unefficient.
So to improve this process I thought that it might be possibly to read the data from the controls via VB WinApi = GetWindowText function.
Unfortunately one can easily get the handles of the controls, but not their content.
I don't know why maybe someone can help me?
If needed I can post the code. Although it works with other programs.
Another way to get the data should be possible if the SAP-Scripting is used.(As a macro or within vba-code)
I tried the macrorecorder, but it doesn't work.
So again I would like to ask for some help for solving this problem.
Thank you very much.
Hello Michael,
here an easy VBA example how to read a text field:
Option Explicit
Sub Test()
Dim SapGuiAuto As Object
Dim Application As SAPFEWSELib.GuiApplication
Dim Connection As SAPFEWSELib.GuiConnection
Dim Session As SAPFEWSELib.GuiSession
Dim TextInField As String
Set SapGuiAuto = GetObject("SAPGUI")
If Not IsObject(SapGuiAuto) Then
Exit Sub
End If
Set Application = SapGuiAuto.GetScriptingEngine()
If Not IsObject(Application) Then
Exit Sub
End If
Set Connection = Application.Connections(1)
If Not IsObject(Connection) Then
Exit Sub
End If
Set Session = Connection.Sessions(0)
If Not IsObject(Session) Then
Exit Sub
End If
Session.StartTransaction "SE16"
Session.FindById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").Text = "TOADV"
'-Get the content of the field in a variable-
TextInField = Session.FindById("wnd[0]/usr/ctxtDATABROWSE-TABLENAME").Text
'-Now you can use the content to send it via API SetWindowText or in your office application
Debug.Print TextInField
Set Session = Nothing
Set Connection = Nothing
Set Application = Nothing
Set SapGuiAuto = Nothing
End Sub
Cheers
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.