I have some filters applied on my input excel sheets, so I decided to remove them using showAllData()
method in vb.net.
MSDN Reference : http://msdn.microsoft.com/en-us/library/bb178108(v=office.12).aspx
But it is giving a very strange exception on that line : Exception from HRESULT: 0x800A03EC
My code :
sh = myWorkBook.Sheets(2)
' sh is my sheet
sh.Visible = True
sh.Activate()
sh.Select()
sh.ShowAllData() ' Exception raised on this line
What am I doing wrong ?
What is this exception, I have seen this a lot lately. But its never clear what went wrong ?
Got it fixed :
The sheets that I was using for input didn’t had filtered data when tested.
So, here goes the code change :
sh = myWorkBook.Sheets(2)
' sh is my sheet
sh.Visible = True
sh.Activate()
sh.Select()
If sh.FilterMode = True Then
sh.ShowAllData()
End If
The extra if
, solved the issue.
But still the raised exception was not at all helpful. Explain the exception if someone can.
Answer:
But still the raised exception was not at all helpful. Explain the exception if someone can.
ShowAllData() gives an error if the data is not filtered and hence you have to check for it as you rightly did 🙂
Here is another way to do it
On Error Resume Next
xlsheet.ShowAllData()
On Error GoTo 0
And to remove the AutoFilter you can use this code
If xlsheet.AutoFilterMode = True Then xlsheet.AutoFilterMode = False
Tags: excel, exception, vb.net, vb.net.net