几年来,我一直在使用一些脚本,这些脚本在SAP中创建报告,将数据保存到Excel文件中,并在Excel中使用VBA脚本处理这些数据。
几天后它就不能正常工作了。有时它工作得很好,但下一次运行它会失败。数据由Excel处理,但之后SAP不会停止运行VB脚本。不幸的是,我不知道脚本停止工作的确切行。
问我们的IT人员,他说我们在过去的几周里把我们的SAP-Gui和我们的办公室改成了Office365。
这是代码的结尾,从调用VBA-Script开始。
'***** 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
发布于 2021-03-12 19:36:47
我能想到的第一件事是,您确定要处理连接到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这样,每当你的代码崩溃或者程序结束时,所有的对象都会被设置为"Nothing“。
如果有帮助,请让我知道!
https://stackoverflow.com/questions/50503114
复制相似问题