【问题标题】:Object required error on Set session = Connection.Children(0)Set session = Connection.Children(0) 上的 Object required 错误
【发布时间】:2014-06-10 14:18:35
【问题描述】:

我正在尝试启动 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

【问题讨论】:

  • 在每个“set XXX =”之后添加:if XXX is nothing then msgbox "the thing above is broken"
  • runtime error '424' Object required and VBA 突出显示以下行 Set session = Connection.Children(0)

标签: excel vba sap-gui


【解决方案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.

【讨论】:

    【解决方案2】:

    如果在 Edgar M 的建议后仍然出现问题(将 connection 更正为 SAPCon),
    尝试在设置会话之前添加一点延迟.. (或在发生悬挂的那条线之前) .. 所以在这种情况下,SAPCon 有足够的时间(在运行环境中)在代码继续之前完成(与更快地获得 pc 相关?)。
    比如:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-14
      • 1970-01-01
      • 2019-04-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多