Invoke Code doesn't work when trying to manipulate Excel because of missing Assemblies

Hey All, I have an issue with executing code to modify excel file throuh invoke code activity in UiPath

This is the kind of errors I got :

Main has thrown an exception

Source: Invoke code

Message: Error compiling code
error BC31539: Cannot find the interop type that matches the embedded type ‘Microsoft.Office.Interop.Excel._Application’. Are you missing an assembly reference? At line 1
error BC31539: Cannot find the interop type that matches the embedded type ‘Microsoft.Office.Interop.Excel.Workbooks’. Are you missing an assembly reference? At line 2
error BC31539: Cannot find the interop type that matches the embedded type ‘Microsoft.Office.Interop.Excel.Workbook’. Are you missing an assembly reference? At line 3
error BC30002: Type ‘Microsoft.Office.Interop.Excel.ApplicationClass’ is not defined. At line 5

Exception Type: ArgumentException

System.ArgumentException: Error compiling code
error BC31539: Cannot find the interop type that matches the embedded type ‘Microsoft.Office.Interop.Excel._Application’. Are you missing an assembly reference? At line 1
error BC31539: Cannot find the interop type that matches the embedded type ‘Microsoft.Office.Interop.Excel.Workbooks’. Are you missing an assembly reference? At line 2
error BC31539: Cannot find the interop type that matches the embedded type ‘Microsoft.Office.Interop.Excel.Workbook’. Are you missing an assembly reference? At line 3
error BC30002: Type ‘Microsoft.Office.Interop.Excel.ApplicationClass’ is not defined. At line 5

at UiPath.Core.Activities.Workflow.CompilerRunner.Compile(String code, Int32 errLineOffset, Boolean generateInMemory)
at UiPath.Core.Activities.Workflow.CompilerRunner…ctor(String code, String className, String methodName, Int32 errLineOffset, Boolean generateInMemory)
at UiPath.Core.Activities.InvokeCode.GetCompilerRunner(String userCode, List`1 args, String imps)
at UiPath.Core.Activities.InvokeCode.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

PS : I have imported the namespace : Microsoft.Office.Interop.Excel

I have tried solutions presented here : https://forum.uipath.com/t/import-microsoft-office-interop-excel-does-not-work/25453/9
and this added line ( xmlns:moie=“clr-namespace:Microsoft.Office.Interop.Excel;assembly=Microsoft.Office.Interop.Excel” ) gets deleted after each execution of code

and here : https://forum.uipath.com/t/interop-excel-application-is-not-defined/16716/4

But always get that error,

I am using UiPath Studio 2018.1.3 , please help me :slight_smile:

Regards,

Hi There,

Did you get any solution?

Hi,

I had the same issue ,and the following code resolve my issue.

Solution:
To brief up, there can be a various scenario where UiPath gets restricted while importing package and. XAML doesn’t get updated with the required details
In this scenario, I would suggest you add the respective line manually in the xaml.

  1. Close UiPath Studio.
  2. Open the workflow file (xaml) in the notepad or notepad++.
  3. Add the following code xmlns:moio=“clr-namespace:Microsoft.Office.Interop.Excel;assembly=Microsoft.Office.Interop.Excel” on the 4th line of the xaml.
  4. Save it.
  5. Open the workflow in UiPath Studio.
4 Likes

HI @JobinJoy.jnj ,

the added line will be removed, if we make any changes in that workflow in the studio like adding a new variable (meaning to say if we save the file once again in Studio, that added line will be removed).

I think UiPath should come up with the turnaround for this. 18.4.1 version also having the same issue.

Regards,
Karthikeyan R

2019-05-01T05:00:00Z

This is still an issue.
Invoke code activity will not allow excel code.

Hi Everyon ,@Binary_Avenger, @Pratiksha @Ahmed_benj ,

I found an solution.
Please add a new variable to the Workflow of the type (Microsoft.Office.Interop.Excel).

please like and accept the solution if you find useful.

Regards,
Karthikeyan R

2 Likes

hi, could u explain more detail on this?
what kind of variable is it?
and where to use it?
Thanks

1 Like

Create a variable with the type Microsoft.Office.Interop.Excel.Application like below


1 Like

Hi,
may i know why i use this excel version, will get error?

You can use any version.version is not an constraint.

Karthikeyan

not able to open the .xaml in UiPath after adding this line " xmlns:moio=“clr-namespace:Microsoft.Office.Interop.Excel;assembly=Microsoft.Office.Interop.Excel”

I faced the same problem
I fixed it by import a library in packages manger

8 Likes

Thank you Ahmad this worked for me

1 Like

Thanks ahmad its work for me :heart_eyes:

Hi below solution worked for me-:
1-Open the first import the “Microsoft.Office.Interop.Word” in the xaml.
2-Open the .xaml file in notepad.
3- Seach for line where test is “namespace:Microsoft.Office.Intereop.Word;assembly=”
4-In “namespace:Microsoft.Office.Intereop.Word;assembly=” put/replace the text in the front of
“assembly” keyword as “Microsoft.Office.Intereop.Word”
So the final text will be
“namespace:Microsoft.Office.Intereop.Word;assembly=Microsoft.Office.Intereop.Word”
5-Save the file and reopen in Uipath.

Thanks

First of all, this worked wonderfully. Thank you for your help! Secondly, can you provide some insight on why declaring a variable fixes the issue?

Thanks a lot