Free Support Forum - aspose.com

Removeat( ) cause error when trying to remove sheets

I am having issues with the removeat() function. I have 3 sheets in my excel designer file. I create an excel sheet and name it “Work Activity Analysis.” When I try to delete the other two sheets using the Removeat() function in a loop I get odd results. The excel file downloads what’s on the current web page instead of what I specify in the create excel function. It almost appears as if the sheet that gets created is also getting removed. When I removed the code below, the excel import works fine, but of course it leaves all 3 sheets in. My only other option is to create an excel designer file for each sheet.


For i = 0 To excel.Worksheets.Count - 1
If (i >= excel.Worksheets.Count) Then
Exit For
End If
If excel.Worksheets(i).Name <> “Work Activity Analysis” Then
excel.Worksheets.RemoveAt(i)
End If
Next

We don’t recommend to use RemoveAt() method for there may be some weird contents in designer files. If you have to use it, please email me your designer file and more of your code. I will investigate it. Thanks for your cooperation.