0

I have created and populated an Excel workbook with 3 worksheets. Sheet1 contains data; Sheet2 and Sheet3 are empty. I massage the data in Sheet1 and enter the output into Sheet2. I would now like to delete Sheet1 and close and save the Excel file.

I am embarressed to say I can't figure out how to delete a worksheet from an Excel spreadsheet in VB6. Hope you can help me out!

2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by binoj_daniel
0

Try this:

Sub DeleteSheets()
dim xl as new excel.application
dim wb as excel.workbook
set wb=xl.workbooks.open("c:\test.xls"
xl.application.displayalerts=false
If wb.worksheets.count > 1
wb.worksheets(1).delete
End If
xl.application.displayalerts=true
wb.save
wb.close
xl.quit
set wb=nothing
set xl=nothing
End Sub

0

While I would have bet good money I had tried your solution, I am delighted to say it worked. Thanks for your help!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.