Message 1 of 3
Robot Structural Analysis 2025-Close Excel Dynamo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I am trying to use RSA2025 to run dynamo scripts. I am trying to close Excel with the script but I get the following error:
Please find the code from the script below :
import sys
import clr
import System
clr.AddReference('Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')
from Microsoft.Office.Interop import Excel
from System.Runtime.InteropServices import Marshal
def excel_close(lst_namefile):
xlApp = Excel.Application(Marshal.GetActiveObject("Excel.Application"))
print(xlApp)
allWorkbooks = Excel.Workbooks(xlApp.get_Workbooks())
print([x for x in allWorkbooks])
lst_WkbsName = [Excel.Workbook(x).get_Name() for x in allWorkbooks]
for namefile in lst_namefile:
if namefile in lst_WkbsName:
Tesluiten = Excel.Workbook(allWorkbooks.get_Item(namefile))
Tesluiten.Close()
xlApp.Quit()
toList = lambda x : x if isinstance(x, list) else [x]
OUT = excel_close(toList(IN[0]))
Could you please help me solving this issue?
Best regards,
Stefany