cancel
Showing results for 
Search instead for 
Did you mean: 

exporting table field to excel using sap gui scripting

Former Member
0 Kudos

Hi All,

I am trying to export a table field value from sap to excel i used the the below script as a test for logon

this was working initially but now i am facing an error "Runtime error 429 Activex component can't create object" on this line"Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")".

i used the same computer for both the run.

Sub testlogon()

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

If SapGuiApp Is Nothing Then

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

    End If

If oConnection Is Nothing Then

    Set oConnection = SapGuiApp.OpenConnection("System", 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 = "200"

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

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

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

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

       

    'start extraction

   

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

    .findById("wnd[0]/tbar[0]/okcd").Text = "/NEX"

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

    

     

    End With

     

     Application.DisplayAlerts = True

     MsgBox "SAP session is terminated."

End Sub

Thanks in advance

Regards,

Febin Roy

Accepted Solutions (0)

Answers (1)

Answers (1)

thomas_brutigam2
Active Participant
0 Kudos

Hi Febin,

try this:

should work ...

Former Member
0 Kudos

Hi Thomas,

I tried it,

sapfewse.ocx file was missing initially then i copied it from another computer and added it but no use, i am still facing the same issue


as per Re: Open SAP in Excel I modified the code as below and tried again but the facing syntax error

Automation error - syntax error on line -> Set SAPGUIAuto = GetObject("SAPGUI")

Dim SapGuiApp As SAPFEWSELib.GuiApplication

Dim oConnection As SAPFEWSELib.GuiConnection

Dim SAPSesi As SAPFEWSELib.GuiSession

Dim SAPGUIAuto As Object

Set SAPGUIAuto = GetObject("SAPGUI")

If SapGuiApp Is Nothing Then

    Set SapGuiApp = SAPGUIAuto.GetScriptingEngine

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

    End If