Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6202885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:49:03+00:00 2026-05-24T04:49:03+00:00

I have: Public Class ExcelProcess Private App As New Excel.Application Private Books As Excel.Workbooks

  • 0

I have:

Public Class ExcelProcess
    Private App As New Excel.Application
    Private Books As Excel.Workbooks = App.Workbooks
    Private WB As Excel.Workbook

Public Sub deleteSheets()
    Dim sheet As Excel.Worksheet = getSheetToDelete()
    sheet.Activate()
    sheet.Delete()
    WB.Save()
    WB.Close()
End Sub

Private Function getSheetToDelete() As Excel.Worksheet
     Try
        WB = Books.Open("file.xlsx")
    Catch ex As Exception
        InputOutput.print(ex.Message)
        End
    End Try
    Return WB.Sheets(1)
End Function

End Class

I ran the above code, and it ran successfully with absolutely no errors or exceptions!

But the sheet didn’t get deleted!

< UPDATE >

I have also tried:

sheet.Select()
sheet.Delete()

' Now, this gave me an exception:
Unhandled Exception: System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC
at Microsoft.Office.Interop.Excel._Worksheet.Select(Object Replace)
at DealerCapReport.ExcelProcess.deleteSheets()
at DealerCapReport.MainModule.Main()

< Another UPDATE >

I tried to check sheet.Delete() boolean for success of failure:

If sheet.Delete() Then        ' Error: Expression does not produce a value.
    Console.WriteLine("Can-not Delete")
End If

It says Error: Expression does not produce a value. in sheet.Delete().

The strange thing is that the Microsoft API reference says that it would produce a Boolean, but it doesn’t as it is a Sub and not a function.

How and what is happening?

Am I doing something wrong?

Please help me fix this!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:49:03+00:00Added an answer on May 24, 2026 at 4:49 am

    The following code works for me (EDITED to include some error checking):

    Public Class ExcelProcess
        Private xlApp As Excel.Application
        Private xlBook As Excel.Workbook
        Private xlSheet As Excel.Worksheet
    
        Public Sub New(ByVal file As String)
            xlApp = New Excel.Application
            'xlApp.Visible = True 'for debugging
            xlApp.DisplayAlerts = False 'prevent user dialogs
            xlBook = xlApp.Workbooks.Open(file)
        End Sub
    
        Public Sub Quit()
            If Not IsNothing(xlBook) Then
                xlBook.Save()
                xlBook.Close()
            End If
            If Not IsNothing(xlApp) Then xlApp.Quit()
        End Sub
    
        Public Sub deleteSheet(ByVal Index As Integer)
            If Index > xlBook.Worksheets.Count Then
                Throw New Exception("You cannot delete a worksheet that does not exist")
                Exit Sub
            End If
            If xlBook.Worksheets.Count = 1 Then
                Throw New Exception("You cannnot delete the only worksheet in a workbook")
                Exit Sub
            End If
            xlSheet = CType(xlBook.Worksheets(Index), Excel.Worksheet)
            xlSheet.Activate()
            xlSheet.Delete()
        End Sub
    
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have public class QuantityType { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Key key; @Persistent
I have : public class Person : INotifyPropertyChanged { private string _name; public int
I have public class FundController { private Site _site; public ViewResult Fund() { }
I have public class ListA { private string code; private string name; public string
I have public class ListA { private string code; private string name; public string
(Java Spring WebApp) I have: public class PersonValidator implements Validator { private PersonDAO d;
Here goes an example of what I have: public class ClassToBeTestedTest { private Mock<IAService>
I have the following code: public class NavigationPath { private string menuItems = <li>
Suppose I have public class Parent { private IList<Child> _children; public void AddChild(Child child)
I'm new to Java Threads and synchronization. Lets say I have: public class MyClass(){

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.