cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Gui Script to copy text values to clipboard needed

michael_resnick
Discoverer
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

stefan_schnell
Active Contributor
0 Kudos

Hello Michael,

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

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

Option Explicit

Dim SapGuiAuto, application, connection, session, Text2Clip

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

  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