我试图启动VBS SAP脚本并更改VBS代码的一些变量。
我得到了
运行时错误' 424'需要对象
on 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
答案 0 :(得分:0)
尝试使用此代码:
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
您收到错误消息是因为您缺少对象SAPCon而不是连接,只是偶然发现这个对象并执行您的代码,我遇到了同样的问题并且解决了更改此对象的问题。
最佳,
Edgar M。
答案 1 :(得分:0)
如果在Edgar M的建议(纠正connection
至SAPCon
)后仍然存在问题,则
尝试在设置会话之前添加一点延迟..
(或之前发生悬挂的行)
..所以在这种情况下,SAPCon有足够的时间在代码延续之前完成(在运行环境中)(与更快获得pc的相关?)。
所以喜欢:
..
Set SAPCon = SAPApp.Children(0)
WScript.Sleep 200
Set session = SAPCon.Children(0)
在此之后,随机挂起似乎结束了 最好,JanW