How to stop error messages from showing

G

Guest

I have a spreadsheet that when opened for the first time opens to a sheet
named start and all other sheets are hidden. You click on a button that says
start and it runs this script:

Private Sub cmdactivation_Click()
'1)unhide sheets, 2)create datasheet, 3)delete sheet3, delete sheet2, select
sheet1, 4)rename, save & close 5)delete start sheet
Sheets("CONTROL PANEL").Visible = True
Workbooks.Add
ActiveWorkbook.SaveAs FileName:= _
"C:\windows\datasheet2006.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
Sheets("Sheet3").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Sheet2").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "datasheet"
ActiveWorkbook.Save
ActiveWindow.Close

Sheets("START").Select
On Error Resume Next
Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete
Application.DisplayAlerts = True
End Sub

If the datasheet2006.xls it creates already exists I get an error saying it
already exists do I want to replace it. Is there a way to stop the windows
error message from coming up and just replace it by default?

Thanks,
Phil
 
G

Guest

application.DisplayAlerts = False
ActiveWorkbook.SaveAs FileName:= _
"C:\windows\datasheet2006.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
Application.DisplayAlerts = true


or
On Error Resume Next
Kill "C:\windows\datasheet2006.xls"
On Error goto 0
ActiveWorkbook.SaveAs FileName:= _
"C:\windows\datasheet2006.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
 
G

Guest

Beautiful........ thanks Tom. I went with the first suggestion. I actually
had the right idea using the application.displayalerts but I was putting it
around the workbook.add instead of the activeworkbook.saveas filename:=_
So I was putting it in the wrong place. Thanks for the help, worked great.

Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top