[英]Close sap export multiple excel file with vba
This is my code for SAP GUI script in which on click of button i am exporting a data to file.这是我的 SAP GUI 脚本代码,单击按钮我将数据导出到文件中。 i have mutiple rows there would be 100's of file are generated.我有多个行,将生成 100 个文件。 i have to manually close all file.我必须手动关闭所有文件。
can anybody help how to close the all new opened excel file.任何人都可以帮助如何关闭所有新打开的 excel 文件。 What code should i add in it我应该在其中添加什么代码
Dim ws As Worksheet
Dim lrow As Long
Set ws = ThisWorkbook.Worksheets("Sheet1")
Dim lastrow As Long
lastrow = ws.UsedRange.Rows.Count
If Not IsObject(SAPApp) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set SAPApp = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(Connection) Then
Set Connection = SAPApp.Children(0)
End If
If Not IsObject(session) Then
Set session = Connection.Children(0)
End If
If IsObject(wscript) Then
wscript.ConnectObject session, "on"
wscript.ConnectObject Application, "on"
End If
lrow = ws.Cells(Rows.Count, "A").End(xlUp).Row
For i = 2 To lrow
If ws.Cells(i, "G") = True Then
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").Text = "/nfbl3n"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/radX_AISEL").Select
session.findById("wnd[0]/usr/ctxtSD_SAKNR-LOW").Text = ws.Range("A" & i)
session.findById("wnd[0]/usr/ctxtSD_SAKNR-HIGH").Text = ws.Range("B" & i)
session.findById("wnd[0]/usr/ctxtSD_BUKRS-LOW").Text = ws.Range("C" & i)
session.findById("wnd[0]/usr/ctxtSD_BUKRS-HIGH").Text = ws.Range("D" & i)
session.findById("wnd[0]/usr/ctxtSO_BUDAT-LOW").Text = ws.Range("E" & i)
session.findById("wnd[0]/usr/ctxtSO_BUDAT-HIGH").Text = ws.Range("F" & i)
session.findById("wnd[0]/usr/ctxtSO_BUDAT-HIGH").SetFocus
session.findById("wnd[0]/usr/ctxtSO_BUDAT-HIGH").caretPosition = 10
session.findById("wnd[0]/tbar[1]/btn[8]").press
session.findById("wnd[0]/mbar/menu[0]/menu[3]/menu[1]").Select
session.findById("wnd[1]/tbar[0]/btn[0]").press
session.findById("wnd[1]/usr/ctxtDY_PATH").Text = Cells(1, "K").Value
session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = Cells(i, "H").Value
session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 10
session.findById("wnd[1]/tbar[0]/btn[11]").press
End If
Next i
End Sub'''
Everything is evolving.一切都在发展。 Also the possibilities that were known up to now.也是迄今为止已知的可能性。 Recently you could also try the following.最近你也可以试试下面的。 for example:例如:
...
session.findById("wnd[1]/tbar[0]/btn[0]").press
'-------------new-------------------------------------------------------
'Is it really a number = 1 or a parameter = i?
myPath = Cells(1, "K").Value
myFileName = Cells(i, "H").Value
session.findById("wnd[1]/usr/ctxtDY_PATH").Text = myPath
session.findById("wnd[1]/usr/ctxtDY_FILENAME").Text = myFileName
'not necessary and with a file name shorter than 10 it would even be wrong
'session.findById("wnd[1]/usr/ctxtDY_FILENAME").caretPosition = 10
session.findById("wnd[1]/tbar[0]/btn[11]").press
myCount = Workbooks.Count
Do
DoEvents
Application.Wait Now + TimeSerial(0, 0, 5)
DoEvents
If Workbooks.Count > myCount Then Exit Do
Loop
Dim xlApp As Object
Set xlApp = GetObject(myPath & "\" & myFile).Application
For j = 1 To Workbooks.Count
If LCase(Workbooks(j).Name) = LCase(myFile) Then Exit For
Next j
xlApp.Workbooks(j).Close SaveChanges:=False
Set xlApp = Nothing
'--------------new-------------------------------------------------------
Next i
...
Regards, ScriptMan问候,脚本人
Any body know how to handle this -How to Stop the Pop-up;任何人都知道如何处理这个 - 如何停止弹出窗口; SAP GUI Security using VBA script while export the excel SAP GUI Security 在导出 excel 时使用 VBA 脚本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.