cancel
Showing results for 
Search instead for 
Did you mean: 

Method 'Text' of object 'ISapTextFieldTarget' failed

Former Member
0 Kudos

Hi,

I am trying to run a a script via Excel that will log on to SAP and run a report for me. However on occasion I will get the following error:

My code is as follows:


    Dim SapGuiApp As Object

    Dim oConnection As Object

    Dim session As Object

    Dim SAPCon As Object, SAPSesi As Object

    Dim SAPGUIAuto As Object, SAPApp As Object

    Dim sMsg As String

    Dim result As String

    Set SAPSesi = Nothing

    Set SapGuiApp = Nothing

    Set oConnection = Nothing

    If SapGuiApp Is Nothing Then

       Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")

    End If

    SendKeys "{ENTER}"

    If oConnection Is Nothing Then

       Set oConnection = SapGuiApp.OpenConnection(SAPSystemBox.Value, True)

    End If

    If SAPSesi Is Nothing Then

      Set SAPSesi = oConnection.Children(0)

    End If

    Application.DisplayAlerts = False

    With SAPSesi

        .findbyid("wnd[0]/usr/txtRSYST-MANDT").Text = CStr(ClientBox.Value)

The error occurs on the last line that I quoted (.findbyid("wnd[0]/usr/txtRSYST-MANDT").Text = CStr(ClientBox.Value))

Any ideas on how to get past this?

Accepted Solutions (0)

Answers (1)

Answers (1)

holger_khn
Contributor
0 Kudos

Hello. It could be that this field you refer to is not usable in same way as it is in SAPGUI application.

Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")

SAP GUI modal called by this Scripting object is bit different to SAP GUI Dialog.

Former Member
0 Kudos

what else can I use instead of


Holger Kohn wrote:

Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")

, I am opening the SAP session via scripting, based on code I read in this forum

holger_khn
Contributor
0 Kudos

Use one of the open sessions called from SAP GUI. You can check it in document area of this Forum. I have publish a guidance how to Setup an interactive EXCEL MACRO-ENABLED WORKBOOK. This Loop over all existing sessions. In a customized userform you can select one this this list for execution of script.