Exported file opens after macro completes - unwanted

前端 未结 6 678
猫巷女王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 14:06

    I have tried to do what I explained in the comments. It isn't very neat and I wasn't able to test. I only changed a couple of lines to tidy a couple of things up, I dont think that line is needed in the Insert .xlsx from file data section thought. Let me know how you go.

    Sub OriginalSub()
      'Opens SAP connection
      [snip as no change]
    
      'Closes SAP connection
      [snip as no change]
    
      Call ImportData()
    
      Kill "C:\Users\" & Environ("Username") & "\Downloads\SAP_export.XLSX"
    
    End Sub
    
    
    Sub ImportData()
    
    'Clear table from SMS Input
        ThisWorkbook.Worksheets("SMS Input").Cells.ClearContents
    
    'Insert .xlsx file data
        ThisWorkbook.Worksheets("SMS Input").Range("A6").Select
        [snip as no changes from here by me]
    
        Workbooks("SAP_export.XLSX").Close savechanges:=False
    
    End Sub
    

提交回复
热议问题