I am trying to use Invoke Code activity in UiPath. This is the code:
Imports Microsoft.Office.Interop.Excel
Imports Microsoft.Vbe.Interop
Dim excelApp As Application = Nothing
Dim excelWorkbook As Workbook = Nothing
Try
excelApp = New Application()
excelApp.Visible = False
excelWorkbook = excelApp.Workbooks.Open(strExcelPath)
' Use early binding for VBE
Dim vbe As VBE = excelApp.VBE
Dim vbProject As VBProject = vbe.ActiveVBProject
vbProject.VBComponents.Import(strPathVBScript)
excelApp.Run(strMacroName, sheetName, sFilePath)
Catch ex As Exception
Console.WriteLine("Error invoking macro: " & ex.Message)
Finally
If excelWorkbook IsNot Nothing Then
excelWorkbook.Close(False)
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelWorkbook)
excelWorkbook = Nothing
End If
If excelApp IsNot Nothing Then
excelApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp)
excelApp = Nothing
End If
End Try
I won’t even compile. I ran the Analyse File feature and it gave me the following in the Error List:
Error ERROR Validation Error No compiled code to run
error BC30024: Statement is not valid inside a method. At line 1
error BC30024: Statement is not valid inside a method. At line 2
error BC30002: Type 'Application' is not defined. At line 4
error BC30002: Type 'Workbook' is not defined. At line 5
error BC30002: Type 'Application' is not defined. At line 8
error BC30002: Type 'VBE' is not defined. At line 14
error BC30002: Type 'VBProject' is not defined. At line 15
Type 'Application' is missing. You probably need to add an Activity Package to your workflow. Experiments/Exp_Invoke_VBA_Via_Invoke_Mtd.xaml
.
This is the view of the Invoke Code activity:
Can someone kindly assist. Please let me know if you need more from my side. Thank you.
Exp_Invoke_VBA_Via_Invoke_Mtd.xaml (7.6 KB)