首页 > 解决方案 > 有谁知道通过 VBA 自动登录 SAP 的连接代码?

问题描述

我在使用 Windows 10 和 VBA 中的连接代码时遇到问题,无法自动打开 SAP、为我登录并开始宏,是否有适用于 Windows 10 的标准代码?

我有旧版本 Windows 的代码,但我不断收到运行时错误,因为它不完全知道安装的新版本 SAP 是什么/在哪里。

If Sheets("Start").Range("E9") = "Yes" Then
    On Error Resume Next
        Set SapGuiAuto = CreateObject("Sapgui.ScriptingCtrl.1")
        On Error GoTo 0
        If SapGuiAuto Is Nothing Then
             MsgBox "Please start SAPlogon"
             Exit Sub
        End If
        On Error Resume Next
        Set SAP_Applic = SapGuiAuto.GetScriptingEngine
        On Error GoTo 0
        If SAP_Applic Is Nothing Then
             MsgBox "Scripting disabled"
             Exit Sub
        End If
        Set Connection = SAP_Applic.OpenConnection("", True)   'Enter your system here
        Set session = Connection.Children(0)
     If IsObject(WScript) Then
        WScript.ConnectObject session, "on"
        WScript.ConnectObject SAP_Applic, "on"
     End If

标签: vbawindows-10sap

解决方案


推荐阅读