[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.excel.programming

Delete Sheets Problem

joecrabtree

12/18/2006 2:05:00 PM

To all,

I have this code that deletes all but the active worksheets. This
deletes the sheets fine, but then returns the error:

Method 'Delete' of Object_ Worksheets Failed

Any ideas why this is happening?

The code is below:

Dim wks As Worksheet


Application.DisplayAlerts = False
For Each wks In Worksheets
If wks.Name <> ActiveSheet.Name Then wks.Delete
Next wks
Application.DisplayAlerts = True


Thanks in advance for your help,

Regards

Joseph Crabtree

3 Answers

james.billy

12/18/2006 2:15:00 PM

0

Hi,

I have come across this before when trying to delete a sheet that
wasn't visible, is this possible?

James

joecrabtree wrote:
> To all,
>
> I have this code that deletes all but the active worksheets. This
> deletes the sheets fine, but then returns the error:
>
> Method 'Delete' of Object_ Worksheets Failed
>
> Any ideas why this is happening?
>
> The code is below:
>
> Dim wks As Worksheet
>
>
> Application.DisplayAlerts = False
> For Each wks In Worksheets
> If wks.Name <> ActiveSheet.Name Then wks.Delete
> Next wks
> Application.DisplayAlerts = True
>
>
> Thanks in advance for your help,
>
> Regards
>
> Joseph Crabtree

Bob Phillips

12/18/2006 2:17:00 PM

0

Worked fine for me as written.

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"joecrabtree" <thejoecrabtree@gmail.com> wrote in message
news:1166450677.495472.248940@79g2000cws.googlegroups.com...
> To all,
>
> I have this code that deletes all but the active worksheets. This
> deletes the sheets fine, but then returns the error:
>
> Method 'Delete' of Object_ Worksheets Failed
>
> Any ideas why this is happening?
>
> The code is below:
>
> Dim wks As Worksheet
>
>
> Application.DisplayAlerts = False
> For Each wks In Worksheets
> If wks.Name <> ActiveSheet.Name Then wks.Delete
> Next wks
> Application.DisplayAlerts = True
>
>
> Thanks in advance for your help,
>
> Regards
>
> Joseph Crabtree
>


John Bundy

12/18/2006 2:22:00 PM

0

How are you running it? A button click? Works like a charm for me.
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"joecrabtree" wrote:

> To all,
>
> I have this code that deletes all but the active worksheets. This
> deletes the sheets fine, but then returns the error:
>
> Method 'Delete' of Object_ Worksheets Failed
>
> Any ideas why this is happening?
>
> The code is below:
>
> Dim wks As Worksheet
>
>
> Application.DisplayAlerts = False
> For Each wks In Worksheets
> If wks.Name <> ActiveSheet.Name Then wks.Delete
> Next wks
> Application.DisplayAlerts = True
>
>
> Thanks in advance for your help,
>
> Regards
>
> Joseph Crabtree
>
>