cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to find control id through vbscript recording

Former Member
0 Kudos

Hi All,

I am new to scripting , I have automated many tasks of mine through scripting but this one I am facing issue.

I am not able to find control id of SAP APO Optimizer trace file export button ,I want to automate downloading of trace files in text file format  in a particular folder. I have attached trace file screenshot for your reference

Accepted Solutions (0)

Answers (1)

Answers (1)

stefan_schnell
Active Contributor
0 Kudos

Hello Enigma,

you can analyze the the ID with Scripting Tracker.

Here an example to read text from an editor control on the SE80:

Here an example code how to read the content:

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

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

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

    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

    Set TextEdit = session.findById("wnd[0]/usr/subEDITORSUBSCREEN:SAPLEDITOR_START:8430/cntlEDITOR/shellcont/shell")

    MsgBox TextEdit.Text

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

And now you can save the content via FileSystemObject in a file - you can find a good example here.

Cheers

Stefan

Former Member
0 Kudos

Hi Stefan,

I tried to use script editor and the ID for shell is

Set TextEdit=session.findById("wnd[0]/usr/subSUBSCREEN:/SAPAPO/SAPLMSDP_OPTLOG:0201/cntlCNT_0201/shellcont/shell")

But when I execute your given code ,I get the "Expected statement - "error

-Begin-----------------------------------------------------------------

  '-Directives----------------------------------------------------------

    Option Explicit

  '-Global Variables----------------------------------------------------

    Dim SapGuiAuto, application, connection, session, TextEdit

    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

   

   Set TextEdit=session.findById("wnd[0]/usr/subSUBSCREEN:/SAPAPO/SAPLMSDP_OPTLOG:0201/cntlCNT_0201/shellcont/shell")

    MsgBox TextEdit.Text

please help

Former Member
0 Kudos

Hi Stefan ,

I made the above problem go away ,Please find my code below. The problem here is when i execute the code SAP gets hang and it closes.

'-Global Variables----------------------------------------------------

    Dim SapGuiAuto, application, connection, session, TextEdit

    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

   

   Set TextEdit=session.findById("wnd[0]/usr/subSUBSCREEN:/SAPAPO/SAPLMSDP_OPTLOG:0201/cntlCNT_0201/shellcont/shell")

     'TextEdit.Text

  call WriteToFile

  Function WriteToFile

   Const ForReading = 1, ForWriting = 2

   Dim fso, f

   Set fso = CreateObject("Scripting.FileSystemObject")

  Set f = fso.OpenTextFile("c:\testfile.txt", ForWriting, True)

  f.Write TextEdit.text

   Set f = fso.OpenTextFile("c:\testfile.txt", ForReading)

   WriteToFile =   f.TextEdit.text

End Function

stefan_schnell
Active Contributor
0 Kudos

Hello Enigma,

you are on the right way, I modify your code a little bit:

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


  '-Directives----------------------------------------------------------

    Option Explicit


  '-Constants-----------------------------------------------------------

    Const ForWriting = 2


  '-Global Variables----------------------------------------------------

    Dim SapGuiAuto, application, connection, session, TextEdit, text


  '-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


    "Set here your correct ID

    text = session.findById("wnd[0]/usr/cntlEDITOR/shellcont/shell").Text

    Call WriteToFile(text)

  '-Sub WriteToFile-----------------------------------------------------

    Sub WriteToFile(FileContent)

      Dim fso, f

      Set fso = CreateObject("Scripting.FileSystemObject")

      Set f = fso.OpenTextFile("c:\dummy\testfile.txt", ForWriting, True)

      f.Write FileContent

      f.Close()

    End Sub


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

Let us know your results.

Cheers

Stefan

Former Member
0 Kudos

Hi Stefan,

The problem remains the same .as soon as f.Write FileContent begins to write the file SAP system hangs and closes with ther error message.  I think file to write is quite large between 5 to 10 mb. Simple "Hello world" I am able to write in txt format  by this method.

Is there a way to write big chunk of data maybe line by line or maybe copy and paste through script  or any other way.

waiting for your suggestion.

Regards,

Enigma

stefan_schnell
Active Contributor
0 Kudos

Hello Enigma,

I never have tried it with so big data. In my test case I use it with 10 MB and if I call the Text property I get an exception with the code 80010105. It seems necessary to save the file via button "Save as local file".

Try this to open the dialog:

TextEdit.ContextMenu

TextEdit.SelectContextMenuItemByPosition "18"

Here you find a description how to work with Windows Save as dialog.

Let us know your results.

Cheers

Stefan