G
Guest
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", Structure:=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
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", Structure:=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