0

I want to start the SAP LogonPad with the .ini file, that works fine.

Then after binding to the scripting object I want to open the connection to a specific System with connection = SapGui.OpenConnection("SID", True) but I always get this error:

runtime error 70 access denied.

I followed what others seem to do with VBS, for certain reasons I can't do it with VBS and have to go with VBA, so maybe there might be some difference that makes it fail?

Any advice would be highly appreciated.

Private Sub CommandButton1_Click()

    Dim SapGui As Object
    Dim saplogon As Object
    Dim connection 'As Object

    Set SapGui = GetObject("SAPGUI")

    Dim Wshshell As Object
    Set Wshshell = CreateObject("Wscript.Shell")

    Wshshell.Run Chr(34) & ("C:\Program Files\SAPPC\FrontEnd\SAPgui
    \saplogon.exe") & Chr(34) & " " & "/INI_FILE" & "=" & Chr(34) & 
    "\\longpathtoini\appl\Sap\saplogon\int\saplogon.ini" & Chr(34)

    Do Until Wshshell.AppActivate("SAP Logon")
        Application.Wait Now + TimeValue("0:00:01")
    Loop

    Set Wshell = Nothing

    Set saplogon = SapGui.GetScriptingEngine
    connection = SapGui.OpenConnection("SID", True)

    Set SapGui = Nothing
    Set saplogon = Nothing
    Set connection = Nothing

End Sub
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
JonSnow
  • 9
  • 1
  • 5

2 Answers2

1

Check whether user scripting is allowed for the particular system (transaction RZ11, parameter sapgui/user_scripting). Also be aware that for some versions, you'll apparently need to specify the SAP Logon entry text instead of the SID.

vwegert
  • 18,371
  • 3
  • 37
  • 55
  • Scripting on the servers is active. I just did uncheck alsoo the setting of SAP Gui to warn if a script connects. Weird is, It did open the SAP-System Logon Screen just once. Now I get runtime error 438 Object doesn't support this property or method. – JonSnow May 15 '16 at 10:10
0

Thanks to vwegert.

I surely knew about scripting needs to be enabled on the servers. Which is, but at the moment I read his answer I remembered that in my SAP GUI settings the checkbox for "Warn if a script tries to connect" was enabled.

Disabeling that options did lead to success.

The above code works perfectly.

JonSnow
  • 9
  • 1
  • 5