I'm trying to run my first python script (newbie) to open an excel book, run and macro, and close the book. The macro is running just fine, but I'm getting a few traceback errors that I'm really struggling to understand. The other issue appears to be that excel remains open once the script has run (although the worksheet itself has closed).
Here's the script (some parts are omitted with '...'):
import os, os.path
import win32com.client
if os.path.exists("S:\...\Warehouse Inventory Template for Customer.xlsm"):
xl=win32com.client.Dispatch("Excel.Application")
wb = xl.Workbooks.Open(os.path.abspath("S:\...\Warehouse Inventory Template for Customer.xlsm"), ReadOnly=1)
xl.Application.Run("'Warehouse Inventory Template for Customer.xlsm'!CustomerInventoryUpdate")
wb.Close(False)
#xl.Application.Quit()
del wb
del xl
The macro runs fine here, but then:
> Traceback (most recent call last):
> File "T:\...\Python\Scripts\customerstockfeed.py", line 7, in <module>
> xl.Application.Run("'Warehouse Inventory Template for Customer.xlsm'!Main.CustomerInventoryUpdate") File "<COMObject
> <unknown>>", line 8, in Run File
> "C:\Users\...\AppData\Local\Programs\Python\Python311\Lib\site-packages\win32com\client\dynamic.py",
> line 368, in _ApplyTypes_
> result = self._oleobj_.InvokeTypes( pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0,
> -2146788248), None)