Skip to Content

SAP Gui Script to copy text values to clipboard needed

Hi All -

New to SAP and never created a SAP GUI script before so this may be easy for some.  I have a custom page in SAP that has 20 text fields on it.  I need to be able to grab the value in any of the 20 fields and place the values into the clipboard.  There are 20 fields but not all will have values.

There will always be a value in the first field:


but there may or may not be a value in any of the other 19


. . .


The values can be up to 10 characters each and when placed into the clipboard, I need the values with a CR+LF following each so that when pasted they show up as



Can anyone create this script for me?



Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Dec 11, 2014 at 07:44 AM

    Hello Michael,

    here an example how to copy data from SAP text fields to the clipboard via Internet Explorer inside SAP GUI Scripting:


        Option Explicit

      '-Global Variables----------------------------------------------------
        Dim SapGuiAuto, application, connection, session, Text2Clip

      '-Sub setClipData-----------------------------------------------------
        Sub setClipData(Text2Clip)

            Dim oIE

          Set oIE = CreateObject("InternetExplorer.Application")
          If IsObject(oIE) Then
            oIE.document.parentWindow.clipboardData.setData "text", Text2Clip
            Set oIE = Nothing
          End If

        End Sub

        If Not IsObject(application) Then
          Set SapGuiAuto = GetObject("SAPGUI")
          Set application = SapGuiAuto.GetScriptingEngine
        End If

        If Not IsObject(connection) Then
          Set connection = application.Children(0)
        End If

        If Not IsObject(session) Then
          Set session = connection.Children(0)
        End If

        Text2Clip = session.findById("wnd[0]/usr/txtRSYST-MANDT").text
        Text2Clip = Text2Clip & vbCrLf
        Text2Clip = Text2Clip & _



        Set session = Nothing
        Set connection = Nothing
        Set application = Nothing
        Set SapGuiAuto = Nothing


    With this example you read the fields mandant and user name from the logon screen and put it to the clipboard.

    Enjoy it.



    Add comment
    10|10000 characters needed characters exceeded