cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Scripting x GuiXT

Former Member
0 Kudos

Hello, everyone.

I have been trying to use scripting in SAP (run SAP transactions from VBS / VBA codes in Excel) for quite a long time.

Despite Scripting being enabled in my SAP configuration, I have never succeeded in finding a code that, at least, could LOGON SAP.

All i've tried have resulted in different kinds of errors.

examples: GetObject("SAPGUI"); or the ones using RFC connections (which say i dont have enough authorization).

Another example: following code, error in line 37 (   Set SAPSesi = oConnection.Children(0))


Sub Macro2()

'

' Macro2 Macro

'

'

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 sapConnection As Object

Set WshShell = CreateObject("WScript.Shell")

Set proc = WshShell.Exec("C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe /ini_file=C:\Users\myname\AppData\Roaming\SAP\Common\COPSAPLOGON.INI")

Set SAPGUI = GetObject("SAPGUI")

Set Application = SAPGUI.GetScriptingEngine

Set Connection = Application.openconnection("wwwwwwwwww", True)

If SapGuiApp Is Nothing Then

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

End If

If oConnection Is Nothing Then

    Set oConnection = SapGuiApp.openconnection("wwwwwwwwww", True)

End If

If SAPSesi Is Nothing Then

   Set SAPSesi = oConnection.Children(0)

End If

   

    SAPConnection.Client = "yyy"

    SAPConnection.User = "xxx"

    SAPConnection.Password = "zzzz"

    SAPConnection.Language = "PT"

 

    If nsapConnection.Logon(1, True) = True Then

      MsgBox "No connection to R/3!"

    End If

  

 

    Set SAPCon = SAPApp.Children(0)

    Set SAPSesi = SAPCon.Children(0)

    Application.DisplayAlerts = False

   

With SAPSesi

       

    .findById("wnd[0]/usr/txtRSYST-MANDT").Text = "yyy"

    .findById("wnd[0]/usr/txtRSYST-BNAME").Text = "xxx"

    .findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "zzzz"

    .findById("wnd[0]/usr/txtRSYST-LANGU").Text = "PT"

    .findById("wnd[0]").sendVKey 0

       

    'start extraction

   

    .findById("wnd[0]").maximize

   

    End With

My question is: How can I have NO authorization for RFC but have scripting enabled to user and also being able to use GUIXT (and all of its functions... like create pushbuttons, record some transactions - but only in sap- , etc)?

Sorry if i've said something wrong, Im in a "learning process"

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello! Does anybody have any ideas?