I have an excel spreadsheet where I want to pragmatically load Capital IQ plugin and perform certain macros. I am currently using pywin32 to open excel and load the plugin. For some apparent reason the cap IQ plugin is not able to load when I perform actions such as setting the Connect property to False then True (or only setting to true). Does anyone have any idea how I go about with loading the Cap IQ plugin with excel. Any info would be greatly appreciated.
def wait_for_ciq_addin(excel):
retries = 20
while retries > 0:
try:
ciq_addin = excel.Application.COMAddIns.Item("SNL.Clients.Office.Excel.ExcelAddIn")
ciq_addin.Connect = False
time.sleep(30)
ciq_addin.Connect = True
time.sleep(30)
if ciq_addin.Connect:
print("Capital IQ Add-In loaded.")
return True
except Exception as e:
print(f"Waiting for Capital IQ Add-In to load... {retries} retries left. Error: {str(e)}")
time.sleep(1)
retries -= 1
print("Capital IQ Add-In did not load in the expected time.")
return False
def run_macro(excel, macro_name):
try:
excel.Application.Run(macro_name)
print(f"Macro {macro_name} executed successfully.")
except Exception as e:
print(f"Failed to run macro {macro_name}. Error: {str(e)}")
def main():
excel = win32com.client.Dispatch("Excel.Application")
excel.Visible = True
workbook_path = r"PATH"
workbook = excel.Workbooks.Open(workbook_path)
if wait_for_ciq_addin(excel):
# Run the macro
macro_name = "Module1.Macro"
run_macro(excel, macro_name)
workbook.Close(SaveChanges=False)
excel.Quit()
when I perform actions, such as setting the Connect property to False then True (or only setting to true). The plugin is still not connected/recognized