【问题标题】:VB-Script sleeps after calling VBA-ScriptVB-Script 在调用 VBA-Script 后休眠
【发布时间】:2018-05-24 07:08:54
【问题描述】:

几年以来,我一直在使用一些脚本,这些脚本在 SAP 中创建报告,将数据保存到 Excel 文件中,并在 Excel 中使用 VBA 脚本处理这些数据。

几天后,它不再正常工作了。有时它工作正常,但下一次运行它失败。 数据由 Excel 处理,但之后 SAP 不会停止运行 VB 脚本。不幸的是,我不知道脚本停止工作的确切位置。

问我们的 IT 人员,他说我们在过去几周的某个时候将 SAP-Gui 和 Office 更改为 Office365。

代码到此结束,从调用 VBA 脚本开始。

'***** Report über Excel-Makro auswerten *****
wshell.run chr(34) & "\\denbppfs002\Abteilungslaufwerke\Produktion\Produktionsreporting\Makros\Autostart OpenProcessOrders.xlsm" & chr(34),1,true

'wscript.sleep 4000 

If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If

while connection.children.count > 0
Set asession = connection.Children(0)
asession.findbyid("wnd[0]").close
on error resume next
asession.findById("wnd[1]/usr/btnSPOP-OPTION1").press
on error goto 0
wend

有人知道问题出在哪里吗?

感谢您的帮助, 卢茨

【问题讨论】:

  • 如果您的系统上安装了适当的调试器(例如 Visual Studio),并且设置正确,那么当您使用 cscript.exe your_script_name.vbs //X //D 运行脚本时,您可以逐行执行脚本时间,看看它到底在哪里下落。
  • 您好 Zev,很遗憾我的系统上没有调试器。
  • 我会先修剪脚本并删除 wshell.run 后面的命令。然后我会启动删节的脚本,看看它的表现如何。远程线路仅实现所有打开的 SAP 会话的关闭。然后我会将这些行放在一个新脚本中,并另外提供 msgbox“位置 1”、msgbox“位置 2”等,这样我就知道他在处理过程中走了多远,或者循环中的哪个点无限长地旋转.

标签: excel sap-gui


【解决方案1】:

我能想到的第一件事是,您确定要处理连接到 SAP 的 VBA 对象吗?我的意思是在“Autostart OpenProcessOrders.xlsm”中调用的部分

我认为您的解决方案的问题是在当前执行结束之前无法调用您的下一次迭代,SAP 将允许您一次只运行一个脚本。

看这里:

Public Sub GetWorkDone

    Dim SapGuiAuto As Object
    Dim app As SAPFEWSELib.GuiApplication
    Dim connection As SAPFEWSELib.GuiConnection
    Dim session As SAPFEWSELib.GuiSession

    On Error Goto Dispose
        
        Set SapGuiAuto = GetObject("SAPGUI")
        Set app = SapGuiAuto.GetScriptingEngine
        Set connection = app.Children(0)
        Set session = connection.Children(0)
        
        'Your code goes here
        
    On Error Goto 0

    Dispose:

        Set session = Nothing
        Set connection = Nothing
        Set app = Nothing
        Set SapGuiAuto = Nothing
    
End Sub

这样,每当您的代码运行失败或程序刚结束时,所有对象都将设置为“无”。

如果有帮助,请告诉我!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-07
    • 2011-08-23
    • 2017-03-21
    • 1970-01-01
    • 2012-08-24
    • 2018-01-27
    相关资源
    最近更新 更多