Revit 2025, MIcrosoft.Office.Interop.Excel issue

Hello everyone, I have started trying some of my scripts in revit 2025 and I got an error when I tried to load Microsoft.Office.Interop.Excel.

This only happens in revit 2025, 2024 and 2023 works fine, same pyRevit version.

I will appreciate any help on this

Regards

Script Executor Traceback:
System.IO.FileNotFoundException: Could not load file or assembly ‘Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’. The system cannot find the file specified.
File name: ‘Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’
at System.Reflection.RuntimeAssembly.g____PInvoke|49_0(NativeAssemblyNameParts* __pAssemblyNameParts_native, ObjectHandleOnStack __requestingAssembly_native, StackCrawlMarkHandle __stackMark_native, Int32 __throwOnFileNotFound_native, ObjectHandleOnStack __assemblyLoadContext_native, ObjectHandleOnStack __retAssembly_native)
at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext, RuntimeAssembly requestingAssembly, Boolean throwOnFileNotFound)
at System.Reflection.Assembly.Load(String assemblyString)
at Microsoft.Scripting.PlatformAdaptationLayer.LoadAssembly(String name)
at IronPython.Runtime.ClrModule.AddReferenceByName(CodeContext context, String name)
at IronPython.Runtime.ClrModule.AddReferenceByName(CodeContext context, String names)
at Microsoft.Scripting.Interpreter.ActionCallInstruction2.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3) at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2) at Microsoft.Scripting.Interpreter.DynamicInstruction4.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.HandleException(InterpretedFrame frame, Exception exception)
at Microsoft.Scripting.Interpreter.Interpreter.HandleException(InterpretedFrame frame, Exception exception)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
at IronPython.Runtime.PythonContext.InitializeModule(String fileName, ModuleContext moduleContext, ScriptCode scriptCode, ModuleOptions options)
at IronPython.Runtime.Importer.LoadFromDisk(CodeContext context, String name, String fullName, String str)
at IronPython.Runtime.Importer.ImportFromPathHook(CodeContext context, String name, String fullName, List path, Func5 defaultLoader) at IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path) at IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, String name) at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globals, String modName, Boolean bottom, Int32 level) at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist, Int32 level) at IronPython.Runtime.Operations.PythonOps.ImportBottom(CodeContext context, String fullName, Int32 level) at Microsoft.Scripting.Interpreter.FuncCallInstruction4.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
at Microsoft.Scripting.Hosting.CompiledCode.Execute(ScriptScope scope)
at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)

hej @sanzoghenzo & @rtorrez ,
for me this issues does not seems to be resolved.
my script still work in revit 2023 as it did before but 2025 is still bugged and not adding the reference to assembly.
Ps.: i am using the lastest version of pyrevit to date: [pyRevit v5.1.0 - Revit 2026 Support]

this is my code and error:

# -*- coding: utf-8 -*-

"""

Excel utility functions for reading and writing data to Excel files.

"""

# ===================================================

# IMPORTS

# ===================================================

import clr, os, sys, shutil

# Add .NET Interop Reference

clr.AddReference('Microsoft.Office.Interop.Excel')

from Microsoft.Office.Interop import Excel # type: ignore

ERROR:

IronPython Traceback:
Traceback (most recent call last):
 File "C:\Users\AlexanderV\AppData\Roaming\pyRevit\Extensions\BBpy\BBpy.extension\BBpy.tab\Import & Export.panel\Schedules.stack\ExportMS.Pushbutton\script.py", line 24, in <module>
 File "C:\Users\AlexanderV\AppData\Roaming\pyRevit\Extensions\BBpy\BBpy.extension\lib\excelUtils.py", line 12, in <module>
IOError: System.IO.IOException: Could not add reference to assembly Microsoft.Office.Interop.Excel
 at IronPython.Runtime.ClrModule.AddReference(CodeContext context, String name)
 at IronPython.Runtime.ClrModule.AddReference(CodeContext context, Object[] references)
 at Microsoft.Scripting.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
 at IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
 at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
 at IronPython.Runtime.PythonContext.InitializeModule(String fileName, ModuleContext moduleContext, ScriptCode scriptCode, ModuleOptions options)
 at IronPython.Runtime.Importer.LoadFromDisk(CodeContext context, String name, String fullName, String str)
 at IronPython.Runtime.Importer.ImportFromPathHook(CodeContext context, String name, String fullName, List path, Func`5 defaultLoader)
 at IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path)
 at IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, String name)
 at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globals, String modName, Boolean bottom, Int32 level)
 at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist, Int32 level)
 at IronPython.Runtime.Importer.ImportLightThrow(CodeContext context, String fullName, PythonTuple from, Int32 level)
 at Microsoft.Scripting.Interpreter.FuncCallInstruction`5.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
 at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
 at Microsoft.Scripting.Hosting.CompiledCode.Execute(ScriptScope scope)
 at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)

Script Executor Traceback:
System.IO.IOException: Could not add reference to assembly Microsoft.Office.Interop.Excel
 at IronPython.Runtime.ClrModule.AddReference(CodeContext context, String name)
 at IronPython.Runtime.ClrModule.AddReference(CodeContext context, Object[] references)
 at Microsoft.Scripting.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
 at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
 at IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)
 at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
 at IronPython.Runtime.PythonContext.InitializeModule(String fileName, ModuleContext moduleContext, ScriptCode scriptCode, ModuleOptions options)
 at IronPython.Runtime.Importer.LoadFromDisk(CodeContext context, String name, String fullName, String str)
 at IronPython.Runtime.Importer.ImportFromPathHook(CodeContext context, String name, String fullName, List path, Func`5 defaultLoader)
 at IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path)
 at IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, String name)
 at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globals, String modName, Boolean bottom, Int32 level)
 at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist, Int32 level)
 at IronPython.Runtime.Importer.ImportLightThrow(CodeContext context, String fullName, PythonTuple from, Int32 level)
 at Microsoft.Scripting.Interpreter.FuncCallInstruction`5.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
 at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
 at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
 at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)
 at Microsoft.Scripting.Hosting.CompiledCode.Execute(ScriptScope scope)
 at PyRevitLabs.PyRevit.Runtime.IronPythonEngine.Execute(ScriptRuntime& runtime)

Try using pyRevit/site-packages/xlsxwriter at 9e1ccbc5ba5a81dfb03de279ca156caa963ea119 · pyrevitlabs/pyRevit · GitHub

And have a look at all the linked refered in the issue. Plenty of other ways to solve the PB.

1 Like

@Jean-Marc thx, i always just read the issue on github and foudn the xl, xlrd and xlwriter modules.
i have for tool long been avoinding and now that i use them they are so much easier then i thought :blush: .

I read the article from Gavincrump on the dynamo forums, concering the Cpython situation.
What is your feedback on this?
Should it be best to convert all my scripts to Cpython (engine)?
How ould i then best approach UI elements in scripts?

thx for the answer, i’ll close the issues here.

I would not go the cpython road just now. Not close to being ready. I have bigger hopes around Autodesk releasing eventually an open source pythonnet3 engine, the one they develop for dynamo (this is an option but not settled on the dynamo/Autodesk team side from my latest discussions with Sol)

UI wise, personally I keep thinks simple and use the forms module extensively. You can understand my reluctance to go to cpython.

1 Like

Hi Jean-Marc,

what is the way to go for writing in an existing excel file?
I don’t see any functionality for in that in the interop.xl nor in the xlsxwriter.
They only write new excel files.

i was able to create create a lot of excel read script and i’m now working on the write side of things but can’t seems to find alot of material on this.