Exported file opens after macro completes - unwanted

前端 未结 6 704
猫巷女王i
猫巷女王i 2020-12-18 13:30

I have some VBA code that exports SAP data to a .XLSX file, then imports this file into excel. After the file is imported, I have code that performs many other actions (eg p

6条回答
  •  忘掉有多难
    2020-12-18 13:43

    Today I saw another solution to the problem. I really wanted to share it with you.

    for example:

    ...
    ' Export from SAP to .xlsx file.
    Session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").contextMenu
    Session.findById("wnd[0]/usr/cntlGRID1/shellcont/shell").selectContextMenuItem "&XXL"
    Session.findById("wnd[1]/tbar[0]/btn[0]").press
    Session.findById("wnd[1]/usr/ctxt[0]").Text = "C:\tmp"
    Session.findById("wnd[1]/usr/ctxt[1]").Text = "SAP_export.XLSX"
    Session.findById("wnd[1]/tbar[0]/btn[11]").press
    
    
    Dim xlApp As Object
    Application.Wait Now + TimeSerial(0, 0, 5)
    
    Set xlApp = GetObject("c:\tmp\SAP_export.XLSX").Application
    
    xlApp.Workbooks(1).Close False
    'xlApp.Quit
    ...
    

    Regards, ScriptMan

提交回复
热议问题