1

Using win32com to interact with Excel:

import win32com.client
...
self.excel = win32com.client.gencache.EnsureDispatch("Excel.Application")
self.workbook = self.excel.Workbooks.Add()
#Modify the workbook...
self.workbook.SaveAs(...)
self.excel.Quit()

This works well and generates a new Excel-Document in the background (headless mode) as long as no instance of Excel is already running before the script is started.

However, if the user already had Excel open, the Excel-Instance created by the Python script becomes visible. How can I prevent that from happening? Even worse, when the user is doing any action (like clicking into a cell) in either of the two Excel-Instances, the script fails:

(ERROR): pywintypes.com_error: (-2146777998, 'OLE error 0x800ac472', None, None)

Is there a way to enforce headless mode and especially to prevent user-actions in the GUI to conflict with the running Python script? In other words, I want the Excel-Instance created by the script to be completely independent of any other Excel-Activity that might be going on.

Krid
  • 95
  • 1
  • 11

1 Answers1

1

The problem is gone when instantiating Excel as described in this answer: https://stackoverflow.com/a/36711595/4721381

Krid
  • 95
  • 1
  • 11