When I try to save the file, it doesn't save and fails.
I get the error:
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', 'Save method of Application class failed', 'xlmain11.chm', 0, -2146827284), None)
Not sure what I'm doing wrong here. Some other posts seem to be pretty old and not relevant.
I saw a post saying to use SaveAs() but that errors out and says AttributeError: <unknown>.SaveAs. Did you mean: 'Save'?
My code:
import os, os.path
import win32com.client
# path = (r'C:\Users\christiansanchez\Downloads\')
if os.path.exists("test_macro.xlsm"):
xl = win32com.client.Dispatch("Excel.Application")
xl.Workbooks.Open(os.path.abspath("test_macro.xlsm"))
xl.Application.Run("test_macro.xlsm!module1.test_macrob")
xl.Application.Save("test_macro.xlsm")
xl.Application.Quit("test_macro.xlsm")
else:
print("error")
.Saveon aWorkbookobject, not theApplication. Btw, I don't thinkQuithas any parameters.xl.Applicationis superfluous.xlalready refers to an Application object, just usexl.Workbooks.Openetc.