title: No RFC authorization for function module RFC PING during SAP logon from VBA
body: <p>Good morning, everybody!</p>
  <p>I've been looking for the solution in the last days but I really have not managed to succeed: I am trying to make a VBA code to:</p>
  <ol>
  <li>log into SAP,</li>
  <li>run some transactions,</li>
  <li>export to excel.</li>
  </ol>
  <p>But even the &quot;log into SAP&quot; part is not OK!</p>
  <p>I tried several codes, the one below OPENS the SAP logon screen, but does not fill in any fields.</p>
  <p>In the first attempt, I Used <code>CreateObject(&quot;Sapgui.ScriptingCtrl.1&quot;)</code>:</p>
  <pre><code>Sub Entrar_SAP()
  
  If Not IsObject(SAPguiApp) Then
      Set SAPguiApp = CreateObject(&quot;Sapgui.ScriptingCtrl.1&quot;)
  End If
  If Not IsObject(Connection) Then
      Set Connection = SAPguiApp.OpenConnection(&quot;xxxxxxx)&quot;, True)
  End If
  If Not IsObject(session) Then
      Set session = Connection.Children(0)
  End If
  session.findById(&quot;wnd[0]/usr/txtRSYST-MANDT&quot;).Text = &quot;100&quot;     
  session.findById(&quot;wnd[0]/usr/txtRSYST-BNAME&quot;).Text = &quot;user&quot;     
  session.findById(&quot;wnd[0]/usr/pwdRSYST-BCODE&quot;).Text = &quot;pass&quot; 
  session.findById(&quot;wnd[0]/usr/txtRSYST-LANGU&quot;).Text = &quot;PT&quot; 
  session.findById(&quot;wnd[0]/usr/txtRSYST-LANGU&quot;).SetFocus     
  session.findById(&quot;wnd[0]/usr/txtRSYST-LANGU&quot;).caretPosition = 2 
  session.findById(&quot;wnd[0]&quot;).sendVKey 0
  </code></pre>
  <p>In the second attempt, I tried <code>CreateObject(&quot;SAP.Functions&quot;)</code>, it showed:</p>
  <blockquote>
  <p>&quot;RFC error received. No RFC authorization for function module RFC PING&quot;</p>
  </blockquote>
  <p>The code is:</p>
  <pre><code>'Declaration
  Dim objBAPIControl As Object 'Function Control (Collective object)
  Dim sapConnection As Object 'Connection object
  Set objBAPIControl = CreateObject(&quot;SAP.Functions&quot;)
  Set sapConnection = objBAPIControl.Connection
  sapConnection.Client = &quot;xxxxx&quot; 
  sapConnection.User = &quot;xxxxxx&quot;
  sapConnection.Language = &quot;PT&quot; 
  sapConnection.hostname = &quot;xxxxx&quot;
  sapConnection.Password = &quot;xxxxxxxx&quot; 'Fake password         
  sapConnection.SystemNumber = &quot;4&quot;
  sapConnection.System = &quot;xxxxxx)&quot;
  sapConnection.Logon 
  If sapConnection.Logon(1, True) &lt;&gt; True Then
      MsgBox &quot;No connection to R/3!&quot;
  Exit Sub 'End program 
  End If
  </code></pre>
  <p>Can someone please help me? Thanks!!</p>