I would imagine the
InStr(eItem.Name, s)=0
is evaluating to False

If you run it on the same workbook, the first time all the WS are deleted,
so there are no more that qualify the second time.

NickHK

"kotelok" <kotelok.2cquff_1155918007.0754@excelforum-nospam.com> 撰寫於郵件新聞:kotelok.2cquff_1155918007.0754@excelforum-nospam.com...
>
> I have several report templates (spreadsheets) in one workbook. A user
> can select one (or more) reports in vb screen (application is written
> in vb 6), data from a database are processed and send to the Excel
> template - then unnecessary worksheets are deleted. It works perfectly
> at the first run. If I repeat the procedure -
> Application.DisplayAlerts=False does not work, in other words excessive
> worksheets are not being deleted. Magic!
> This is the procedure:
> Public Sub RemoveExtraSheets(ByRef s As String)
>
> Dim eItem As Excel.Worksheet
>
> For Each eItem In xlAppl.ActiveWorkbook.Worksheets
>
> Application.DisplayAlerts = False
>
> If InStr(eItem.Name, s) = 0 Then
> eItem.Delete
> End If
> Next
> Application.DisplayAlerts = True
>
> End Sub
>
>
> --
> kotelok
> ------------------------------------------------------------------------
> kotelok's Profile:
> http://www.excelforum.com/member.php...o&userid=37725
> View this thread: http://www.excelforum.com/showthread...hreadid=571110
>