0

I'm using python 2.7.11 on a windows 10 machine where I'm updating a file using VBA contained in the Update_table.xls worksheet. I'm using the below code but I am finding that the Excel worksheet sometimes remains open in the task manager once the py script has ran.

import win32com.client
xl=win32com.client.Dispatch("Excel.Application")
xl.Workbooks.Open(Filename="C:\Projects\Update_table.xlsb",ReadOnly=1)
xl.Application.Run("Update2")
xl = 0

As I am running multiple scripts at once is there a way to ensure the workbook is closed? & not close the whole excel application.

Lee Murray
  • 315
  • 1
  • 6
  • 19

1 Answers1

1

Not sure what you mean by running multiple scripts at once, but to close the workbook:

wb = xl.Workbooks.Open(Filename="C:\Projects\Update_table.xlsb",ReadOnly=1)
...
wb.Close()
wb = None
Oliver
  • 27,510
  • 9
  • 72
  • 103