从 VBA 运行 VBS SAP 生成需要对象的错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24143399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running VBS SAP from VBA generates Object required error
提问by Formatted
I'm trying to start a VBS SAP script and to change some of the variables of the VBS code.
我正在尝试启动 VBS SAP 脚本并更改 VBS 代码的一些变量。
I get
我得到
Runtime error '424' Object required
运行时错误“424”需要对象
on Set session = Connection.Children(0)
在 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
回答by user4114827
Try with this code:
尝试使用此代码:
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
You are getting the error message because you are missing the object SAPCon in istead of connection, just chance this object and execute your code, I was facing same issue and it was solved changing this object.
您收到错误消息是因为您缺少对象 SAPCon 而不是连接,只是碰巧这个对象并执行您的代码,我遇到了同样的问题,并且解决了更改此对象的问题。
Best,
最好的事物,
Edgar M.
埃德加 M。
回答by Jan W Roosch
if still hang problems after advice by Edgar M ( correcting connection
to SAPCon
),
try adding a little delay before Set session..
(or before which ever line where the hanging occurs)
.. so in this case SAPCon has enough time to complete (within the run environment) before code continuation (related to ever faster getting pc's?).
So like:
如果仍然由埃德加·M(挂修正建议后问题connection
来SAPCon
),
尝试设置会话之前加入少许延迟。(或之前它在哪里发生挂有史以来线)..所以在这种情况下SAPCon有足够的时间来完成(内运行环境)在代码继续之前(与更快地获取 pc 相关?)。
所以像:
..
Set SAPCon = SAPApp.Children(0)
WScript.Sleep 200
Set session = SAPCon.Children(0)
After this, the random hangs seemed over.
Best, JanW
在此之后,随机挂起似乎结束了。
最好的,JanW