User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 456,507 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,661 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 2533 | Replies: 3 | Solved
Reply
Join Date: Sep 2007
Location: Atlanta, Georgia, USA
Posts: 2
Reputation: wmr30075 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
wmr30075 wmr30075 is offline Offline
Newbie Poster

Delete an Excel worksheet using VB6

  #1  
Sep 25th, 2007
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!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Location: United States
Posts: 613
Reputation: binoj_daniel is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 15
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Solution Re: Delete an Excel worksheet using VB6

  #2  
Sep 25th, 2007
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
Reply With Quote  
Join Date: Sep 2007
Location: Atlanta, Georgia, USA
Posts: 2
Reputation: wmr30075 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
wmr30075 wmr30075 is offline Offline
Newbie Poster

Re: Delete an Excel worksheet using VB6

  #3  
Sep 26th, 2007
While I would have bet good money I had tried your solution, I am delighted to say it worked. Thanks for your help!
Reply With Quote  
Join Date: Dec 2006
Location: United States
Posts: 613
Reputation: binoj_daniel is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 15
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: Delete an Excel worksheet using VB6

  #4  
Sep 26th, 2007
No Problem. Anytime. You can contribute on my site too. here
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 3:43 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC