Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Open and LOGON on SAP with Excel Macro

Hi,

i am trying to start SAP from excel VBA and input my information, like Log in, user name, password, etc.

To sum up, SAP is not open. I want to open it by clicking on the macro it will also input my user name and password into SAP.

Here is my coding.


When I click on the macro, its give me the following. (see image).


Any help?


Sub macro2()



Dim sapConn As Object

Set objshell = CreateObject("WScript.Shell")
Set objapp = objshell.Exec("C:\Program Files\SAP\FrontEnd\SAPgui\saplogon.exe")
Set sapConn = CreateObject("SAP.Functions") 'Create ActiveX object

  sapConn.connection.ApplicationServer = "C:\Program Files\SAP\FrontEnd\SAPgui\saplogon.exe"
  sapConn.connection.client = "100" ' only read access
  sapConn.connection.user = Environ("USER")
  sapConn.connection.Password = "PASSWORD"
  sapConn.connection.System = ".VCM Global Production"
  sapConn.connection.Language = "EN"
  If sapConn.connection.logon(0, False) <> True Then 'Try Logon
  MsgBox "Cannot Log on to SAP"
  getSAPProjectHours = False
  Else
  
  sapConn.connection.Logoff
  End If
  Set sapConn = Nothing

End Sub

result.JPG (53044 B)
Former Member
Not what you were looking for? View more on this topic or Ask a question