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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with objects

Status
Not open for further replies.

cmz21

Programmer
May 5, 2005
110
US
Hello,
I am using the following code to delete some sheets from a workbook. I keep getting the error: "Object doesn't support this method or property".
Could someone please tell me the proper object to use with this code?

Thanks


With Excel.ActiveWorkbook
.DisplayAlerts = False
.Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
.ActiveWindow.SelectedSheets.Delete
End With
 
DisplayAlerts = False
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
ActiveWindow.SelectedSheets.Delete

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
So I don't have to use a with statment?
 
DisplayAlerts and ActiveWindow are properties of the Excel.Application object (not of Workbook)

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

Hi,

You got you tongue wrapped around your eyeteeth...
Code:
    With Application
        .DisplayAlerts = False
        ActiveWorkbook.Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
        .ActiveWindow.SelectedSheets.Delete
    End With

Skip,

[glasses] [red]Be advised:[/red]We know Newton's 3 Laws. But did you hear about the [red]FOURTH???[/red]
Only ONE fig per cookie![tongue]
 
But if I use this code, I get the error "Subscript out of Range" -

With Excel.Application
DisplayAlerts = False
Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
ActiveWindow.SelectedSheets.Delete
End With
 

Code:
    With Excel.Application
        .DisplayAlerts = False
        ActiveWorkbook.Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select
        .ActiveWindow.SelectedSheets.Delete
    End With

Skip,

[glasses] [red]Be advised:[/red]We know Newton's 3 Laws. But did you hear about the [red]FOURTH???[/red]
Only ONE fig per cookie![tongue]
 
Stupid Me........I figured out the problem. I don't think the sheest I am trying to delete exist in the new workbook I am using.

Sorry about that and Thanks alot for your help......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top