5

我正在尝试从 Excel 调用 SAP 事务,我使用了许多来自 Internet 的代码,但仍然失败。不管我使用什么代码,我总是收到相同的错误消息

脚本正在打开与系统 SYSTEM 的连接

比错误说:

运行时错误 1000 错误描述不可用”

比调试后它在下面以黄色突出显示

Set Connection = SapGuiApp.OpenConnection("SYSTEM", True)

它一直在用我试图拉出的所有代码来做这件事。

代码

Dim sap As Object 
Dim conn As Object
 
Sub T_login()
 
    Set sap = CreateObject("SAP.Functions")
    Set conn = sap.Connection
    conn.System = "SYSTEM"
    conn.client = "603"
    conn.user = "LANAX001"
    conn.Password = "alamzeb4"
    conn.Language = "EN"
 
If conn.logon(0, False) Then
    
    MsgBox "Logon to the SAP system is not possible", vbOKOnly, "Comment"
 
Else
 
End If
 
If Not IsObject(SapGuiApp) Then
            
    Set SapGuiApp = CreateObject("Sapgui.ScriptingCtrl.1")
 
End If
 
If Not IsObject(Connection) Then
 
    Set Connection = SapGuiApp.OpenConnection("SYSTEM", True)
 
End If
 
If Not IsObject(session) Then
 
    Set session = Connection.Children(0)     
    'launch a transaction
    session.findById("wnd[0]").Maximize
    session.findById("wnd[0]/tbar[0]/okcd").Text = "FS10N"
    session.findById("wnd[0]").sendVKey 0

End Sub
4

1 回答 1

1

这就是我用来将数据加载到 SAP 的方法——经过验证可以正常工作。HTH。

If Not IsObject(App) Then
   Set SapGuiAuto = GetObject("SAPGUI")
   Set App = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
   Set Connection = App.Children(0)
End If
If Not IsObject(session) Then
   Set session = Connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session, "on"
   WScript.ConnectObject App, "on"
End If

session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nXXXX" 'XXX = your t-code
... ...

之后,这取决于您在 t 代码中执行的操作。

祝你好运!

于 2016-01-30T02:11:28.710 回答