Skip to Content
avatar image
Former Member

Login SAP system using excel macro

Hi Experts,


Trying below mention Code in VBA for Login in SAP
After adding library SAP: Remote Function Call: COM support 1.0 Type Library into VBA

But getting error while running :- "RUN TIME Error '429'
Active X Component can't create object

On debugging showing error in Line 2 " Set sap = CreateObject("SAP.Functions")"


** Please let me know this code also works when user is already Login In SAP**

Dim sap As Object
Dim conn As Object

>> Sub T_login()
>> Set sap = CreateObject("SAP.Functions")
>> Set conn = sap.Connection
>> conn.System = "GEQ"
>> conn.client = "210"
>> conn.user = "n.g"
>> conn.Password = "iel.789"
>> conn.Language = "EN"
>> If conn.logon(0, False) <> True Then
>> MsgBox "Logon to the SAP system is not possible", vbOKOnly, "Comment"
>> Else
>> End If
>> If Not IsObject(SAPguiApp) Then
>> Set SAPguiApp = CreateObject("Sapgui.ScriptingCtrl.1")
>> End If
>> If Not IsObject(Connection) Then
>> Set Connection = SAPguiApp.OpenConnection("SYSTEM", True)
>> End If
>> If Not IsObject(session) Then
>> Set session = Connection.Children(0)
>> End If
>> session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "CLIENT"
>> session.findById("wnd[0]/usr/txtRSYST-BNAME").Text = "USER"
>> session.findById("wnd[0]/usr/pwdRSYST-BCODE").Text = "PASSWORD"
>> session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "EN"
>> session.findById("wnd[0]/usr/txtRSYST-LANGU").SetFocus
>> session.findById("wnd[0]/usr/txtRSYST-LANGU").caretPosition = 2
>> session.findById("wnd[0]").sendVKey 0
>> Set wshell = CreateObject("Wscript.Shell")
>> wshell.Run Chr(34) & Path & "\script.vbs" & Chr(34), 1, 1
>> End Sub
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Aug 18, 2017 at 06:01 AM

    Hello NG,

    do you use x64 version of Office, this could be one reason. I checked it with SAP GUI for Windows 7.40 PL12 and 7.50 PL0, it works with x86 but not with x64 version.

    Let us know.

    Best regards
    Stefa

    Add comment
    10|10000 characters needed characters exceeded