2014-06-10 35 views
0

我想写一个宏来启动一个VBS SAP脚本并可能更改VBS代码的一些变量。任何帮助将是伟大的! 随着下面我得到所需的对象错误从VBA运行VBS SAP对象所需的错误

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 
+1

后每个“'设置XXX ='”补充:'如果XXX是那么没有什么MSGBOX“上面的东西坏了”' –

+0

运行时错误“424” 所需的对象 和VBA突出了以下线 Set session = Connection.Children(0) – Formatted

回答

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 

你所得到的错误消息,因为你是在连接istead失踪的对象SAPCon,只是机会,这对象并执行你的代码,我面临着同样的问题,它解决了改变这个对象。

最佳,

埃德加·M.

0

如果还挂着由埃德加中号建议后问题(修正connectionSAPCon),
尝试添加组会议之前一点点延迟.. (或之前它因此在这种情况下,SAPCon有足够的时间在代码延续之前(在运行环境中)完成(与更快地获得pc的相关?)。
所以像:

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

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

相关问题