Mở tờ khai excel lỗi exception from hresult 0x800a01a8 năm 2024
[{"Line of Business":{"code":"LOB10","label":"Data and AI"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSDLC4","label":"IBM Planning Analytics Advanced"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"204"}] Show
On an example of a simple scenario, this article demonstrates what causes 0x800A01A8 and how to avoid it in C#, VB.NET, VBA, Delphi. Exception from HRESULT: 0x800A01A8 is also known as OLE error 800A01A8 and also known as Object Required. Program. Here’s a method reproducing the issue. The method is an event handler of the Click event of a Ribbon button shown by a PowerPoint add-in. In the method, I get a shape object, retrieve the object’s Parent property, and delete the shape. C#: private void adxRibbonButton1_OnClick(object sender, IRibbonControl control, bool pressed) { }Code samples in VB.NET, VBA, Delphi Scenario. Now run the method, click the Undo command in the PowerPoint UI, run the method again and you see the exception. In this scenario the following properties of the PowerPoint.Shape object produce the same exception: PowerPoint.Shape properties producing 0x800A01A8 in the given scenario Solution. To solve the issue in the example above, release the shape object after you delete it. In C# and VB.NET, you do this by calling System.Runtime.InteropServices.Marshal.ReleaseComObject(titleShape). In VBA and Delphi, just set titleShape to Nothing (VBA) and nil (Delphi). Conclusion. What you saw is just another manifestation of all those problems that occur if you don’t release COM objects in Office solutions. Releasing COM objects immediately after use is the best practice. See also When to release COM objects in Office add-ins developed in .NET. Good luck! Updated on 1-Jul-2014. I gladly accept the suggestion from Fabske. Below are the modified VB.NET and C# versions of the code. These versions demonstrate releasing all COM objects. The suggestion to set the just released variable to null (Nothing in VB.NET) is given in When to release COM objects in Office add-ins developed in .NET I did some research and it seems to do with late binding, code that is giving me the exception follows: Code: Dim ZZ As String = "J" Dim AJ As Excel.Range = CType(wSheet.Columns("A" & ZZ), Range)
I read on msdn if AJ in this case starts out as nothing then vb will throw this exception and to use early binding. I cant bind a column if it hasn't been created yet, so i played around with the placement of the declaration of AJ to no avail, what is the right Direction i should take to fix this issue?
Code: Dim AJ As Excel.Range = CType(wSheet.Columns("AJ"), Range) With AJ > 'For g = 1 To 9 > .Select() > .EntireColumn.ClearContents() > 'ZZ = Chr(Asc(ZZ) + 1) > 'Next > End With I no longer receive the exception but the column does not clear. I tried this simple code: Code: wSheet.Range("AJ").Select() > wSheet.Range("AJ").ClearContents() throws this Exception from HRESULT: 0x800A03EC The VB help file states: To work around this behavior, use early-bound objects or pass a variable instead of a property of the object. Is this saying that i need to specify what "AJ" is before the excel code even executes? Or, should i dim a string variable of "AJ" then use the variable instead of actually typing "AJ"?
|