cancel
Showing results for 
Search instead for 
Did you mean: 

error while logging to sap through excel

Former Member
0 Kudos

Hello ,

I am using the below coding

Sub sVBScriptSAP()
On Error Resume Next

If Not IsObject(SAP_applic) Then
        Set SapGuiAuto = GetObject("SAPGUI")
        Set SAP_applic = SapGuiAuto.GetScriptingEngine
End If


er = Err.Number
On Error GoTo 0

If er <> 0 Then
    er = 0
    On Error Resume Next
   
    Call Shell("C:\Program Files\SAP6\SAPgui\saplogon.exe", vbMinimizedFocus)
    Call Shell("C:\Program Files\SAP640\SapGui\saplogon.exe", vbMinimizedFocus)
    On Error GoTo 0

    er = 0
    On Error Resume Next
    If Not IsObject(SAP_applic) Then
        Set SapGuiAuto = GetObject("SAPGUI") 'Setting
        Set SAP_applic = SapGuiAuto.GetScriptingEngine
    End If
   
    er = Err.Number
    On Error GoTo 0
      
    If er <> 0 Then
        tmp = MsgBox("SAP Logon not installed on your system" & vbCrLf & _
            "Please install it using eSupport!", vbInformation)
        End
    End If
End If

Set Connection = SAP_applic.openconnection(SAPBox)
Set Session = Connection.Children(0)

End Sub

When i run the macro , i get error as "error description not available" can u tell me why this error is coming . where i am going wrong .

thanks a lot once again,

Monalisa

Accepted Solutions (1)

Accepted Solutions (1)

script_man
Active Contributor
0 Kudos

Hi Monalisa,

You can try the following:

Sub sVBScriptSAP()

On Error Resume Next

If Not IsObject(SAP_applic) Then

        Set SapGuiAuto = GetObject("SAPGUI")

        Set SAP_applic = SapGuiAuto.GetScriptingEngine

End If

er = Err.Number

On Error GoTo 0

If er <> 0 Then

    er = 0

    On Error Resume Next

  

    Call Shell("C:\Program Files\SAP6\SAPgui\saplogon.exe", vbMinimizedFocus)

    Call Shell("C:\Program Files\SAP640\SapGui\saplogon.exe", vbMinimizedFocus)

    On Error GoTo 0

   

    waitTill = Now() + TimeValue("00:00:01")

    While Now() < waitTill

     DoEvents

    Wend


    er = 0

    On Error Resume Next

    If Not IsObject(SAP_applic) Then

        Set SapGuiAuto = GetObject("SAPGUI") 'Setting

        Set SAP_applic = SapGuiAuto.GetScriptingEngine

    End If

  

    er = Err.Number

    On Error GoTo 0

     

    If er <> 0 Then

        tmp = MsgBox("SAP Logon not installed on your system" & vbCrLf & _

            "Please install it using eSupport!", vbInformation)

        End

    End If

End If

Set Connection = SAP_applic.openconnection("mySAPSystemName")

Set session = Connection.Children(0)

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

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

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

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

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

End Sub

Regards,

ScriptMan

Former Member
0 Kudos

Thank u . I still get the same error .

Where do i get "mysapsystemname".

script_man
Active Contributor
0 Kudos

mySAPSystemName : It is the name of the SAP system from SAP Logon PAD.


In the current system, you can check it as follows::

If Not IsObject(SAP_applic) Then

        Set SapGuiAuto = GetObject("SAPGUI")

        Set SAP_applic = SapGuiAuto.GetScriptingEngine

End If

set Connection = SAP_applic.children(0)

msgbox connection.description

Former Member
0 Kudos

Hello Scriptman,

Is it possible to contact you through email .

If yes, please pass me ur email id .

Thanks

script_man
Active Contributor
0 Kudos

Hi monalisa,

skript.idee at web.de

Regards,

ScriptMan

Former Member
0 Kudos

Thanks a bunch . plz check ur email.

Answers (0)