Copy Excel Chart to Image | Error: 0x8002000B (DISP_E_BADINDEX)

Hi there,

I’m using invoke code to save an excel chart into image with Studio 22.10.x, the reason I’m using invoke is most of the activities for this don’t work on studio 22.10.x.

Dim app As New Microsoft.Office.Interop.Excel.Application
Dim wb As Microsoft.Office.Interop.Excel.Workbook = app.Workbooks.Open("C:\Cashflow (6 Months)_Template.xlsx")
Dim chart1 As Microsoft.Office.Interop.Excel.Chart = CType(wb.Charts("Cashflow_Chart"), Microsoft.Office.Interop.Excel.Chart)
chart1.Export("C:\Cashflow (6 Months)_Template.jpg", "JPG")
wb.Close(False)
wb = Nothing
app.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(app)
app = Nothing

I have imported Microsoft.Office.Interop.Excel, also in my excel I have named chart through excel panel Cashflow_Chart . When I run the workflow I get below error.


System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException: Invalid index. (0x8002000B (DISP_E_BADINDEX))   at Microsoft.Office.Interop.Excel.Sheets.get__Default(Object Index)
   at UiPathCodeRunner_4a6c46e58a0d4265858c4d08f7d383df.Run()
	--- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
   at UiPath.Activities.System.Utilities.InvokeCode.CompilerRunner.Run(Object[] args)
   at UiPath.Activities.System.Utilities.InvokeCode.NetCodeInvoker.Run(String userCode, List`1 inArgs, IEnumerable`1 imps, Object[] args)
   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)

I managed to get a VB.NET code

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.