Initialize/Empty the Workbook

R

rweide

I am trying to initialize (or clean up/empty) all the worksheets in a
workbook. What is the right way to this?
 
A

Alvin Bruney [MVP]

You should iterate the contents of the active workbook and call the delete
method of each worksheet. another approach is to iterate the worksheets
collection calling delete

--
Regards,
Alvin Bruney [Microsoft MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://www.lulu.com/owc
 
R

rweide

Thank you.

This is what I do --

For i = 1 to SS1.Worksheets.Count
SS1.Worksheets(i).Select
SS1.ActiveSheet.Delete
Next

I am still testing to see if this works perfectly.





Alvin Bruney said:
You should iterate the contents of the active workbook and call the delete
method of each worksheet. another approach is to iterate the worksheets
collection calling delete

--
Regards,
Alvin Bruney [Microsoft MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://www.lulu.com/owc
----------------------------------------------------------


rweide said:
I am trying to initialize (or clean up/empty) all the worksheets in a
workbook. What is the right way to this?
 
A

Alvin Bruney [MVP]

Yes that should work. However, you should employ exception handling to catch
the case where the delete fails to work or throws an exception.

--
Regards,
Alvin Bruney [Microsoft MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://www.lulu.com/owc
----------------------------------------------------------


rweide said:
Thank you.

This is what I do --

For i = 1 to SS1.Worksheets.Count
SS1.Worksheets(i).Select
SS1.ActiveSheet.Delete
Next

I am still testing to see if this works perfectly.





Alvin Bruney said:
You should iterate the contents of the active workbook and call the
delete
method of each worksheet. another approach is to iterate the worksheets
collection calling delete

--
Regards,
Alvin Bruney [Microsoft MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ http://www.lulu.com/owc
----------------------------------------------------------


rweide said:
I am trying to initialize (or clean up/empty) all the worksheets in a
workbook. What is the right way to this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top