PDA

View Full Version : Solved: How to stop nuisance warnings



macro_man
04-16-2010, 09:29 AM
I have the following script to create a blank file for uploading. It must be in a text format (.txt) and must contain only one worksheet. My code attemps to delete the excess worksheets but I continue to get the warning message "Data may exist in the sheet(s) selected for deletion. To permanently delete the data, press Delete."

Another message I receive during macro execution comes from saving the file with the same name as one that already exists. The file needs to be a specific name for uploading (I always want the current one replaced). I receive the usual "The file xxx already exists. Do you want to replace the existing file?"

What code would I run to avoid the need of intervening with answers to these warning messages?



Here is the code I use for deleting the extra sheets:


'create new workbook & delete extras:
Workbooks.Add

Sheets("Sheet2").Select


With ActiveWindow
.SelectedSheets.Delete
End With

lucas
04-16-2010, 09:47 AM
Put this before the delete:
Application.DisplayAlerts = False

Be sure to set it back to true before you exit the macro.

mbarron
04-16-2010, 09:49 AM
You can turn the alerts on and off using: Application.DisplayAlerts


Application.Displayalerts = False
With ActiveWindow
.SelectedSheets.Delete
End With
Application.Displayalerts = True

macro_man
04-16-2010, 10:03 AM
Thanks everyone.

I've been wanting to know this for a long time.

Thanks again!!!

Did I forget to say thanks.:mbounce2: