In Windows form Application, Facing this exception
System.Runtime.InteropServices.COMException (0x800A03EC): Cannot insert object.
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Microsoft.Office.Interop.Excel.Shapes.AddOLEObject(Object ClassType, Object Filename, Object Link, Object DisplayAsIcon, Object IconFileName, Object IconIndex, Object IconLabel, Object Left, Object Top, Object Width, Object Height)
Using:
Office 365 and OS windows 10
Application:Windows Application
Target framework: .NET Framework 4.5
Reference: Microsoft.Office.Interop.Excel (version: 14.0.0.0)
I write a function in window application that
add pdf file into Excel sheet.
But I got this error System.Runtime.InteropServices.COMException (0x800A03EC): Cannot insert object
at method
AddOLEObject() .
if (utilities.ctos(drCurrent["drawings"]) != "" && IncludeDetailAttachments)
{
Excel.Shape shape = wsCurrent.Shapes.AddOLEObject(
ClassType: Type.Missing,
Filename: copyToFile,
Link: false,
DisplayAsIcon: true,
IconFileName: "",
IconIndex: 0,
IconLabel: "",
Left: Type.Missing,
Top: Type.Missing,
Width: Type.Missing,
Height: Type.Missing);
shape.Fill.ForeColor.RGB = 500;
shape.Width = 15;
shape.Height = 17;
shape.Left = (float)iconCell.Left + (float)345;
shape.Top = (float)iconCell.Top + (float)1;
shape.Locked = false;
shape.Name = "Detail attachment " + drCurrent["lv1"].ToString() + drCurrent["lv2"].ToString() + drCurrent["lv3"].ToString() + drCurrent["lv4"].ToString() + drCurrent["lv5"].ToString() + drCurrent["lv6"].ToString();
Marshal.ReleaseComObject(shape);
}
What I have tried:
Online suggestion
like
- add/modify Excel workbook SaveAs() method,Interop.Excel.Shapes method AddOLEObject(),
- PROVIDE PERMISSION UNDER DCOMCNFG
- UPDATE version Microsoft.Office.Interop.Excel (latest to lowest one by one, execute with each)