on 01-22-2019 6:11 AM
Restored question from @tybtech aka Will Hankins, 2019/01/22
Hello all,
I have seen this question asked a few times, but I can't find an answer that I've been able to use. The issue is simple. When exporting data from SAP GUI as spreadsheet, a new instance of Excel is automatically opened with the freshly exported data. How can I stop this? I am aware of workarounds such as exporting as a local file, but sometimes these don't format correctly.
I've tried changing some settings in Excel but nothing works. Any advice?
Thanks,
Will
I encountered the same problem when I tried to automatically export and save as excel file for 1000 tables. After exporting a table to excel file, SAP automatically opens the downloaded file in another Excel Instance. I could not find any settings in SAP to turn off the auto-open so I have been using this code to quit other instances of Excel leaving the only instance of Excel in which my macro is running:
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Sub closeOtherExcelInstances()
Dim oServ As Object
Dim cProc As Variant
Dim oProc As Object
Dim currentProcId
currentProcId = GetCurrentProcessId
Set oServ = GetObject("winmgmts:")
Set cProc = oServ.ExecQuery("Select * from Win32_Process where NAME = 'EXCEL.EXE'")
For Each oProc In cProc
If oProc.ProcessId <> currentProcId Then
Debug.Print oProc.Name, oProc.ProcessId
errReturnCode = oProc.Terminate()
End If
Next
End Sub<br>
Update 08.04.2019
As I dug deeper to find acceptable solution for this matter. Something likes this also worth trying:
Sub close_excel_instance_sap()
' Variable to store other excel instance'
Dim xlApp As Object
' some codes to export to excel from sap'
' Wait for other excel instance opened by SAP to appear'
Application.Wait Now + TimeSerial(0, 0, 5)
' because after exporting to excel file, sap will open this exported excel file with another instance of Excel'
' so we need to close that instance'
' this code will give us access to other instance of Excel'
' It only works if you enter the fullpath of the exported excel file. Just the filename of the workbook will not work'
Set xlApp = GetObject(REPLACE_WITH_FULL_PATH_TO_EXPORTED_WORKBOOK).Application
' do something with the exported workbook'
' close the exported workbook'
xlApp.Workbooks(1).Close False
' close the excel instance'
xlApp.Quit
End Sub
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
9 | |
8 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.