Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Error when deleting sheets

when I run the following code... I get a 1004 error saying a can't delete the
worksheet I have specified. (something like a bad delete method).

any ideas?


Sheets("DATA").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Agencies").Select
ActiveWorkbook.Protect Password:="test", Structu=True, Windows:=False
sFilename = "S:\Inventory\" & "SNW Inventory " &
Format(Worksheets("Data").Range("g1").Value, "yyyy-mm-dd")
ans = MsgBox("Save file as " & sFilename)
If ans = vbOK Then
ActiveWorkbook.SaveAs Filename:=sFilename
End If
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
ActiveSheet.Unprotect Password:="test"
Application.DisplayAlerts = False
Sheets("Muni's").Select
ThisWorkbook.Sheets("Muni's").Delete
Sheets("Agencies").Select
Application.DisplayAlerts = True

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Error when deleting sheets

Try changing
ThisWorkbook.Sheets("Muni's").Delete
to
Activesheet.Delete
--
HTH...

Jim Thomlinson


"John" wrote:

when I run the following code... I get a 1004 error saying a can't delete the
worksheet I have specified. (something like a bad delete method).

any ideas?


Sheets("DATA").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Agencies").Select
ActiveWorkbook.Protect Password:="test", Structu=True, Windows:=False
sFilename = "S:\Inventory\" & "SNW Inventory " &
Format(Worksheets("Data").Range("g1").Value, "yyyy-mm-dd")
ans = MsgBox("Save file as " & sFilename)
If ans = vbOK Then
ActiveWorkbook.SaveAs Filename:=sFilename
End If
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
ActiveSheet.Unprotect Password:="test"
Application.DisplayAlerts = False
Sheets("Muni's").Select
ThisWorkbook.Sheets("Muni's").Delete
Sheets("Agencies").Select
Application.DisplayAlerts = True

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Error when deleting sheets

That didn't do it... it says

Delete Method of Worsheet Class failed...

Is there a way to access the menu and go to edit, then delete worksheet?

"Jim Thomlinson" wrote:

Try changing
ThisWorkbook.Sheets("Muni's").Delete
to
Activesheet.Delete
--
HTH...

Jim Thomlinson


"John" wrote:

when I run the following code... I get a 1004 error saying a can't delete the
worksheet I have specified. (something like a bad delete method).

any ideas?


Sheets("DATA").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Agencies").Select
ActiveWorkbook.Protect Password:="test", Structu=True, Windows:=False
sFilename = "S:\Inventory\" & "SNW Inventory " &
Format(Worksheets("Data").Range("g1").Value, "yyyy-mm-dd")
ans = MsgBox("Save file as " & sFilename)
If ans = vbOK Then
ActiveWorkbook.SaveAs Filename:=sFilename
End If
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
ActiveSheet.Unprotect Password:="test"
Application.DisplayAlerts = False
Sheets("Muni's").Select
ThisWorkbook.Sheets("Muni's").Delete
Sheets("Agencies").Select
Application.DisplayAlerts = True

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Error when deleting sheets

You protected the structure of the workbook, which means you can't delete
sheets. You would have to unprotect the structure of the workbook before
deleting the sheet.

--
Regards,
Tom Ogilvy

"John" wrote in message
...
when I run the following code... I get a 1004 error saying a can't delete

the
worksheet I have specified. (something like a bad delete method).

any ideas?


Sheets("DATA").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Agencies").Select
ActiveWorkbook.Protect Password:="test", Structu=True,

Windows:=False
sFilename = "S:\Inventory\" & "SNW Inventory " &
Format(Worksheets("Data").Range("g1").Value, "yyyy-mm-dd")
ans = MsgBox("Save file as " & sFilename)
If ans = vbOK Then
ActiveWorkbook.SaveAs Filename:=sFilename
End If
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
ActiveSheet.Unprotect Password:="test"
Application.DisplayAlerts = False
Sheets("Muni's").Select
ThisWorkbook.Sheets("Muni's").Delete
Sheets("Agencies").Select
Application.DisplayAlerts = True

End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Error when deleting sheets

You protected the workbook:
ActiveWorkbook.Protect
But you unprotected the worksheet:
ActiveSheet.Unprotect Password:="test"

Try unprotecting the workbook instead.


John wrote:

when I run the following code... I get a 1004 error saying a can't delete the
worksheet I have specified. (something like a bad delete method).

any ideas?

Sheets("DATA").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Agencies").Select
ActiveWorkbook.Protect Password:="test", Structu=True, Windows:=False
sFilename = "S:\Inventory\" & "SNW Inventory " &
Format(Worksheets("Data").Range("g1").Value, "yyyy-mm-dd")
ans = MsgBox("Save file as " & sFilename)
If ans = vbOK Then
ActiveWorkbook.SaveAs Filename:=sFilename
End If
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
ActiveSheet.Unprotect Password:="test"
Application.DisplayAlerts = False
Sheets("Muni's").Select
ThisWorkbook.Sheets("Muni's").Delete
Sheets("Agencies").Select
Application.DisplayAlerts = True

End Sub


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Error when deleting sheets

wow, I feel a little silly... thanks

"Dave Peterson" wrote:

You protected the workbook:
ActiveWorkbook.Protect
But you unprotected the worksheet:
ActiveSheet.Unprotect Password:="test"

Try unprotecting the workbook instead.


John wrote:

when I run the following code... I get a 1004 error saying a can't delete the
worksheet I have specified. (something like a bad delete method).

any ideas?

Sheets("DATA").Select
ActiveWindow.SelectedSheets.Visible = False
Sheets("Agencies").Select
ActiveWorkbook.Protect Password:="test", Structu=True, Windows:=False
sFilename = "S:\Inventory\" & "SNW Inventory " &
Format(Worksheets("Data").Range("g1").Value, "yyyy-mm-dd")
ans = MsgBox("Save file as " & sFilename)
If ans = vbOK Then
ActiveWorkbook.SaveAs Filename:=sFilename
End If
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Attachments.Add ActiveWorkbook.FullName
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
ActiveSheet.Unprotect Password:="test"
Application.DisplayAlerts = False
Sheets("Muni's").Select
ThisWorkbook.Sheets("Muni's").Delete
Sheets("Agencies").Select
Application.DisplayAlerts = True

End Sub


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
deleting sheets 2&3 doug53098 Excel Discussion (Misc queries) 2 July 7th 05 08:22 PM
deleting sheets KLP Excel Discussion (Misc queries) 3 January 14th 05 12:24 AM
Deleting Sheets Jordan[_3_] Excel Programming 4 February 13th 04 03:19 PM
Deleting sheets Gary Adamson[_2_] Excel Programming 2 October 30th 03 07:24 PM
deleting sheets david Excel Programming 2 July 31st 03 01:02 AM


All times are GMT +1. The time now is 10:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"