You haven't provided working code, so I'm reduced to guessing. However, you may well have a mistake that I often kick myself for making. Excel renumbers sheets after each insert and delete. Therefore, if you have code anything like:
for (1..2) {$wb->Sheets($_)->Delete;}
(untested), and there are two sheets in the book, what will happen is that sheet 1 will be deleted, sheet 2 will be re-indexed to 1 and then the attempt to delete sheet 2 will crash, because there is now only 1 sheet in the book.

Another possibility is that you should be using Sheets() instead of Worksheets(). Working code really does help us to help you. We don't want business logic - we're far more interested in Perl! But, as others have said, please don't shout.

Regards,

John Davies

Update: another possibility is that you are trying to delete every sheet in the book. That will never work - Excel can't accept books with no sheets.

In reply to Re: How to delete Excel worksheets using Win32::OLE by davies
in thread HowTo Delete Excel Worksheets Using WIN32::OLE by sachin_p_ganjare

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.