Question: File already exists

M

Michael Vaughan

Hello Everyone,

I have written a macro so that it formats some code, creates another
workbook, and then saves the code to the harddrive. It all works fine, but
I want to save it to the same file name everytime. Is there a command that
I can write that will AUTOMATICALLY save the file and overwrite the file???
After the script runs, then a msgbox pops up and always asks, "calander.csv
already exists, do you want to overwrite??" Can I write some code that will
do that? Here is the code I have now:

ChDir "C:\Program Files\InternetMacros\Downloads"
ActiveWorkbook.SaveAs Filename:= _
"C:\Program Files\InternetMacros\Downloads\calander.csv",
FileFormat:=xlCSV, _
CreateBackup:=False

Any help would be greatly appreciated,

Michael Vaughan
 
D

Dave Peterson

application.displayalerts=false
'your code here
application.displayalerts=true
 
T

Tom Ogilvy

ChDir "C:\Program Files\InternetMacros\Downloads"
Application.displayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
"C:\Program Files\InternetMacros\Downloads\calander.csv",
FileFormat:=xlCSV, _
CreateBackup:=False
Application.DisplayAlerts = True

or
Dim sStr as String
ChDir "C:\Program Files\InternetMacros\Downloads"
sStr = "C:\Program Files\InternetMacros\Downloads\calander.csv"
On Error Resume Next
Kill sStr
On Error goto 0
ActiveWorkbook.SaveAs Filename:=sStr, _
FileFormat:=xlCSV, _
CreateBackup:=False
 

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