troubleshooting Question

vb.net deleting excel sheet in workbook

Avatar of AlexPonnath
AlexPonnathFlag for United States of America asked on
Visual Basic.NETMicrosoft OfficeMicrosoft ExcelVB Script
11 Comments1 Solution1402 ViewsLast Modified:
I am using some very basic code to test my app where i open a Excel Workbook, count the nbr of sheets in beginning
then delete 1 sheet and then count sheets again and save. For some reason i can not actually delete sheet, the sheet
count is same before and after delete and after save the sheet is still in work book. Hope someone can see what i am doing wrong here

Dim oExcel As Object = CreateObject("Excel.Application")
Dim oBook As Object = oExcel.Workbooks.Open("C:\Users\Documents\acme.xls")

Dim oSheet As Object = oBook.Worksheets(2)

MsgBox(oBook.Worksheets.count)

oSheet.Delete()

MsgBox(oBook.Worksheets.count)

oBook.SaveAs("C:\Users\Documents\ACME-New.xls",)
oExcel.Quit()
ASKER CERTIFIED SOLUTION
Shums
Excel VBA Developer
Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros