1

我正在尝试启动 SAP GUI 脚本并更改 VBA 代码的一些变量。

我明白了

运行时错误“424”需要对象

Set session = Connection.Children(0)

Public Sub SimpleSAPExport()
Set SapGuiAuto = GetObject("SAPGUI")  'Get the SAP GUI Scripting object
Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
Set SAPCon = SAPApp.Children(0) 'Get the first system that is currently connected
Set session = Connection.Children(0) 'Get the first session (window) on that connection

'  Start the transaction to view a table
session.StartTransaction "SE16"
end sub
4

2 回答 2

1

您收到错误消息是因为该对象Connection不存在,只需将此对象更改为实际对象SAPCon并执行您的代码。我遇到了同样的问题,并解决了改变这个对象:

Set SapGuiAuto = GetObject("SAPGUI") 'Get the SAP GUI Scripting object
Set SAPApp = SapGuiAuto.GetScriptingEngine 'Get the currently running SAP GUI
Set SAPCon = SAPApp.Children(0) 'Get the first system that is currently connected
Set session = SAPCon.Children(0) 'Get the first session (window) on that connection

最好的,

埃德加 M。

于 2014-10-06T20:45:28.727 回答
0

如果在 Edgar M 的建议之后仍然出现挂起问题 (更正connection为运行环境)在代码继续之前(与更快地获得电脑有关?)。 就像:SAPCon

..
Set SAPCon = SAPApp.Children(0)
WScript.Sleep 200
Set session = SAPCon.Children(0)

在此之后,随机挂起似乎结束了。
最佳,JanW

于 2015-05-07T14:11:34.597 回答