ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Tool_Box/ExcelRunningConnector.py
Revision: 953
Committed: Wed Nov 5 18:23:42 2025 UTC (4 months, 3 weeks ago) by nino.borges
Content type: text/x-python
File size: 623 byte(s)
Log Message:
My favorite way to connect and manipulate a running Excel workbook.

File Contents

# Content
1 """
2
3 ExcelRuningConnector
4
5 Created by:
6 Emanuel Borges
7 07.25.2025
8
9 A library for connecting to an already running Excel instance.
10
11 """
12
13
14 import time
15
16 from win32com.client import GetActiveObject
17
18
19 def get_excel_app_with_retry(retries=5, delay=1):
20 for attempt in range(retries):
21 try:
22 xlApp = GetActiveObject("Excel.Application")
23 return xlApp
24 except Exception as e:
25 print(f"Attempt {attempt+1}: Excel not ready. Retrying in {delay}s...")
26 time.sleep(delay)
27 raise RuntimeError("Failed to connect to Excel after multiple attempts.")