首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VB-Script在调用VBA-Script后休眠

VB-Script在调用VBA-Script后休眠
EN

Stack Overflow用户
提问于 2018-05-24 15:08:54
回答 1查看 83关注 0票数 2

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

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

问我们的IT人员,他说我们在过去的几周里把我们的SAP-Gui和我们的办公室改成了Office365。

这是代码的结尾,从调用VBA-Script开始。

代码语言:javascript
复制
'***** 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

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

谢谢你的帮助,Lutz

EN

回答 1

Stack Overflow用户

发布于 2021-03-12 19:36:47

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

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

请看这里:

代码语言:javascript
复制
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

这样,每当你的代码崩溃或者程序结束时,所有的对象都会被设置为"Nothing“。

如果有帮助,请让我知道!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50503114

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档