import win32com.client from pathlib import Path def refresh(filename_str: str): filename = Path(filename_str) excel = win32com.client.Dispatch("Excel.Application") excel.DisplayAlerts = False print(f"Refresh '{filename.resolve()}'") wb = excel.Workbooks.Open(filename.resolve()) try: for source in wb.LinkSources(1): print(" --> " + source) if Path(source).exists(): excel.Workbooks.Open(source) else: print(" !! does not exist !!") except TypeError: print(" --> " + "no LinkSources") wb.RefreshAll() wb.Save() wb.Close(True) excel.Application.Quit()