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:

session.findById("wnd[0]/usr/txtZF1").text

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

session.findById("wnd[0]/usr/txtZF2").text

. . .

session.findById("wnd[0]/usr/txtZF20").text

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

VALUE1
VALUE2
VALUE3

etc...

Can anyone create this script for me?

Thanks,

MDR

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:


    '-Begin-----------------------------------------------------------------

      '-Directives----------------------------------------------------------
        Option Explicit

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

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

          '-Variables-------------------------------------------------------
            Dim oIE

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

        End Sub

      '-Main----------------------------------------------------------------
        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 & _

          session.findById("wnd[0]/usr/txtRSYST-BNAME").text

        setClipData(Text2Clip)

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

    '-End-------------------------------------------------------------------

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

    Enjoy it.

    Cheers

    Stefan

    Add comment
    10|10000 characters needed characters exceeded