I\'ve seen from various questions on here that if an instance of Excel is opened from Python using:
xl = win32com.client.gencache.EnsureDispatch(\'Excel.Applicat
I have had much better success using Excel via win32com than any of the other methods, but you might want to look at pyxll (https://www.pyxll.com/introduction.html). Here are a few other things:
addin.Installed == True
? AddIns.Add("c:\windows\addins\TSXL\TSXL.xll").Installed = True
?xl.DisplayAlerts=False
before opening the workbooksHave you tried the four steps in last answer of Automating Excel via COM/Python - standard addins won't load at startup, I copy them here:
I have actually managed to resolve this by borrowing something from this MSDN article relating to doing the same thing with VBA:
http://support.microsoft.com/default.aspx?scid=KB;en-us;q213489
The following now works perfectly:
xl = win32com.client.gencache.EnsureDispatch('Excel.Application')
xl.Visible = True
xl.RegisterXLL('C:/path/addin.xll')
wb = xl.Workbooks.Open('Test.xlsx')
I had the same problem, but couldn't use xl.RegisterXLL('C:/path/addin.xla')
from the accepted answer, because it only works with .XLL files, and I had a .XLA file.
Instead, I found that this worked:
xl = win32com.client.gencache.EnsureDispatch('Excel.Application')
# Need to load the addins before opening the workbook
addin_path = r'C:\path\addin.xla'
xl.Workbooks.Open(addin_path)
xl.AddIns.Add(addin_path).Installed = True
wb = xl.Workbooks.Open(r"C:\my_workbook.xlsm")