Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send Error Report 2

Status
Not open for further replies.

FJAY

Programmer
Apr 23, 2003
106
0
0
CA
I keep getting a send error report when trying to delete some worksheets using the function or macros below:

Public Sub delete_worksheet()


Dim shtDelWorkSheet As Worksheet

For Each shtDelWorkSheet In Application.Worksheets

Select Case shtDelWorkSheet.Name
Case "SAGE_VAR"
Application.DisplayAlerts = False
Sheets("SAGE_VAR").Select
Sheets("SAGE_VAR").Delete
Application.DisplayAlerts = True

Case "Network_Parameters"
Call remove_objects_NetworkParameters

Case "INTERFACE"
Call remove_objects_interface

Case "InputWindow"

Call remove_objects_InputWindow

Case "SETUP"
Application.DisplayAlerts = False
Sheets("SETUP").Select
Sheets("SETUP").Delete
Application.DisplayAlerts = True

Case "Brew_your_own Templates"
Application.DisplayAlerts = False
Sheets("Brew_your_own Templates").Select
Sheets("Brew_your_own Templates").Delete
Application.DisplayAlerts = True

Case "Brew_NAW"
Application.DisplayAlerts = False
Sheets("Brew_NAW").Select
Sheets("Brew_NAW").Delete
Application.DisplayAlerts = True

Case "Brew_Sprint_IP"
Application.DisplayAlerts = False
Sheets("Brew_Sprint_IP").Select
Sheets("Brew_Sprint_IP").Delete
Application.DisplayAlerts = True

Case Else
'do nothing
End Select
Set shtDelWorkSheet = Nothing
Next

End Sub
 
You may try to replace this:
For Each shtDelWorkSheet In Application.Worksheets
By this:
Dim i As Integer
For i = Application.Worksheets.Count To 1 Step -1
Set shtDelWorkSheet = Application.Worksheets(i)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 


The Worksheets Collection not part of the Application Object. Rather, it is part of the Workbook Object
Code:
For Each shtDelWorkSheet In ActiveWorkbook.Worksheets

Next
BETTER CODE -- NOTICE the shtDelWorkSheet should NOT be deleted!
Code:
Public Sub delete_worksheet()
    Dim shtDelWorkSheet As Worksheet
    
    For Each shtDelWorkSheet In Application.Worksheets
        With shtDelWorkSheet
            Select Case .Name
                Case "SAGE_VAR", "SETUP", "Brew_your_own Templates", "Brew_NAW", "Brew_Sprint_IP"
                    Application.DisplayAlerts = False
                    .Delete
                    Application.DisplayAlerts = True
                    
                Case "Network_Parameters"
                    Call remove_objects_NetworkParameters
                    
                Case "INTERFACE"
                    Call remove_objects_interface
                    
                Case "InputWindow"
                    
                    Call remove_objects_InputWindow
                    
                Case Else
                    'do nothing
            End Select
        End With
    Next
    
End Sub

Skip,
[sub]
[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue][/sub]
 

oops, missed the activeworkbook thing...
Code:
Public Sub delete_worksheet()
    Dim shtDelWorkSheet As Worksheet
    
    For Each shtDelWorkSheet In ActiveWorkbook.Worksheets
        With shtDelWorkSheet
            Select Case .Name
                Case "SAGE_VAR", "SETUP", "Brew_your_own Templates", "Brew_NAW", "Brew_Sprint_IP"
                    Application.DisplayAlerts = False
                    .Delete
                    Application.DisplayAlerts = True
                Case "Network_Parameters"
                    Call remove_objects_NetworkParameters
                Case "INTERFACE"
                    Call remove_objects_interface
                Case "InputWindow"
                    Call remove_objects_InputWindow
                Case Else
                    'do nothing
            End Select
        End With
    Next
    
End Sub

Skip,
[sub]
[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue][/sub]
 
Implemented the feedbacks but I'm still getting the send error report. Thanks.
 


Use your debug [Step] to step thru the code and find out where the error is raised.

Skip,
[sub]
[glasses] [red]A palindrome gone wrong?[/red]
A man, a plan, a ROOT canal...
PULLEMALL![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top